Test sending many events with slow-running execution to validate they get dropped after hitting the max concurrent goroutines
(t *testing.T)
| 166 | // Test sending many events with slow-running execution to validate they get dropped after hitting |
| 167 | // the max concurrent goroutines |
| 168 | func TestSlowExecutionProcessing(t *testing.T) { |
| 169 | ctx := base.TestCtx(t) |
| 170 | terminator := make(chan bool) |
| 171 | defer close(terminator) |
| 172 | base.SetUpTestLogging(t, base.LevelInfo, base.KeyEvents) |
| 173 | |
| 174 | em := NewEventManager(terminator) |
| 175 | em.Start(ctx, 0, -1) |
| 176 | |
| 177 | ids := make([]string, 20) |
| 178 | for i := 0; i < 20; i++ { |
| 179 | ids[i] = fmt.Sprintf("%d", i) |
| 180 | } |
| 181 | |
| 182 | eventForTest := func(i int) (Body, string, base.Set) { |
| 183 | testBody := Body{ |
| 184 | BodyId: ids[i], |
| 185 | "value": i, |
| 186 | } |
| 187 | var channelSet base.Set |
| 188 | if i%2 == 0 { |
| 189 | channelSet = base.SetFromArray([]string{"Even"}) |
| 190 | } else { |
| 191 | channelSet = base.SetFromArray([]string{"Odd"}) |
| 192 | } |
| 193 | return testBody, ids[i], channelSet |
| 194 | } |
| 195 | |
| 196 | resultChannel := make(chan interface{}, 100) |
| 197 | testHandler := &TestingHandler{HandledEvent: DocumentChange, handleDelay: 500} |
| 198 | testHandler.SetChannel(resultChannel) |
| 199 | em.RegisterEventHandler(ctx, testHandler, DocumentChange) |
| 200 | |
| 201 | for i := 0; i < 20; i++ { |
| 202 | body, docid, channels := eventForTest(i % 10) |
| 203 | bodyBytes := base.MustJSONMarshal(t, body) |
| 204 | err := em.RaiseDocumentChangeEvent(ctx, bodyBytes, docid, "", channels, false) |
| 205 | assert.NoError(t, err) |
| 206 | } |
| 207 | |
| 208 | assertChannelLengthWithTimeout(t, resultChannel, 20, 10*time.Second) |
| 209 | |
| 210 | } |
| 211 | |
| 212 | func TestCustomHandler(t *testing.T) { |
| 213 | ctx := base.TestCtx(t) |
nothing calls this directly
no test coverage detected