@@ -41,9 +41,15 @@ func (f *MockDispatcher) DispatchEvent(event LogEvent) (bool, error) {
41
41
return true , nil
42
42
}
43
43
44
+ func NewMockDispatcher (queueSize int , shouldFail bool ) Dispatcher {
45
+ return & MockDispatcher {Events :NewInMemoryQueue (queueSize ), ShouldFail :shouldFail }
46
+ }
47
+
44
48
func TestDefaultEventProcessor_ProcessImpression (t * testing.T ) {
45
49
exeCtx := utils .NewCancelableExecutionCtx ()
46
- processor := NewBatchEventProcessor (WithEventDispatcher (& MockDispatcher {Events : NewInMemoryQueue (100 )}), WithFlushInterval (100 ))
50
+ processor := NewBatchEventProcessor ()
51
+ processor .EventDispatcher = nil
52
+ processor .Start (exeCtx )
47
53
processor .Start (exeCtx )
48
54
49
55
impression := BuildTestImpressionEvent ()
@@ -61,7 +67,7 @@ func TestDefaultEventProcessor_ProcessImpression(t *testing.T) {
61
67
62
68
func TestCustomEventProcessor_Create (t * testing.T ) {
63
69
exeCtx := utils .NewCancelableExecutionCtx ()
64
- processor := NewBatchEventProcessor (WithEventDispatcher (& MockDispatcher { Events : NewInMemoryQueue (100 )} ), WithQueueSize (10 ), WithFlushInterval (100 ))
70
+ processor := NewBatchEventProcessor (WithEventDispatcher (NewMockDispatcher (100 , false ) ), WithQueueSize (10 ), WithFlushInterval (100 ))
65
71
processor .Start (exeCtx )
66
72
67
73
impression := BuildTestImpressionEvent ()
@@ -80,7 +86,7 @@ func TestCustomEventProcessor_Create(t *testing.T) {
80
86
func TestDefaultEventProcessor_LogEventNotification (t * testing.T ) {
81
87
exeCtx := utils .NewCancelableExecutionCtx ()
82
88
processor := NewBatchEventProcessor (WithFlushInterval (100 ), WithQueueSize (100 ),
83
- WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (& MockDispatcher { Events : NewInMemoryQueue (100 )} ),
89
+ WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (NewMockDispatcher (100 , false ) ),
84
90
WithSDKKey ("fakeSDKKey" ))
85
91
86
92
var logEvent LogEvent
@@ -108,13 +114,12 @@ func TestDefaultEventProcessor_LogEventNotification(t *testing.T) {
108
114
err := processor .RemoveOnEventDispatch (id )
109
115
110
116
assert .Nil (t , err )
111
-
112
117
}
113
118
114
119
func TestDefaultEventProcessor_ProcessBatch (t * testing.T ) {
115
120
exeCtx := utils .NewCancelableExecutionCtx ()
116
121
processor := NewBatchEventProcessor (WithFlushInterval (100 ), WithQueueSize (100 ),
117
- WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (& MockDispatcher { Events : NewInMemoryQueue (100 )} ))
122
+ WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (NewMockDispatcher (100 , false ) ))
118
123
processor .Start (exeCtx )
119
124
120
125
impression := BuildTestImpressionEvent ()
@@ -145,8 +150,8 @@ func TestDefaultEventProcessor_ProcessBatch(t *testing.T) {
145
150
146
151
func TestDefaultEventProcessor_QSizeMet (t * testing.T ) {
147
152
exeCtx := utils .NewCancelableExecutionCtx ()
148
- processor := NewBatchEventProcessor (WithQueueSize (2 ), WithFlushInterval (100 ),
149
- WithQueue (NewInMemoryQueue (2 )), WithEventDispatcher (& MockDispatcher { Events : NewInMemoryQueue (100 )} ))
153
+ processor := NewBatchEventProcessor (WithQueueSize (2 ), WithFlushInterval (1000 ),
154
+ WithQueue (NewInMemoryQueue (2 )), WithEventDispatcher (NewMockDispatcher (100 , false ) ))
150
155
processor .Start (exeCtx )
151
156
152
157
impression := BuildTestImpressionEvent ()
@@ -217,7 +222,7 @@ func TestDefaultEventProcessor_FailedDispatch(t *testing.T) {
217
222
func TestBatchEventProcessor_FlushesOnClose (t * testing.T ) {
218
223
exeCtx := utils .NewCancelableExecutionCtx ()
219
224
processor := NewBatchEventProcessor (WithQueueSize (100 ), WithQueue (NewInMemoryQueue (100 )),
220
- WithEventDispatcher (& MockDispatcher { Events : NewInMemoryQueue (100 )} ))
225
+ WithEventDispatcher (NewMockDispatcher (100 , false ) ))
221
226
processor .Start (exeCtx )
222
227
223
228
impression := BuildTestImpressionEvent ()
@@ -239,7 +244,7 @@ func TestBatchEventProcessor_FlushesOnClose(t *testing.T) {
239
244
func TestDefaultEventProcessor_ProcessBatchRevisionMismatch (t * testing.T ) {
240
245
exeCtx := utils .NewCancelableExecutionCtx ()
241
246
processor := NewBatchEventProcessor (WithQueueSize (100 ), WithFlushInterval (100 ),
242
- WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (& MockDispatcher { Events : NewInMemoryQueue (100 )} ))
247
+ WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (NewMockDispatcher (100 , false ) ))
243
248
244
249
processor .Start (exeCtx )
245
250
@@ -273,7 +278,7 @@ func TestDefaultEventProcessor_ProcessBatchRevisionMismatch(t *testing.T) {
273
278
func TestDefaultEventProcessor_ProcessBatchProjectMismatch (t * testing.T ) {
274
279
exeCtx := utils .NewCancelableExecutionCtx ()
275
280
processor := NewBatchEventProcessor (WithQueueSize (100 ), WithFlushInterval (100 ),
276
- WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (& MockDispatcher { Events : NewInMemoryQueue (100 )} ))
281
+ WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (NewMockDispatcher (100 , false ) ))
277
282
278
283
processor .Start (exeCtx )
279
284
@@ -326,7 +331,7 @@ func TestChanQueueEventProcessor_ProcessImpression(t *testing.T) {
326
331
func TestChanQueueEventProcessor_ProcessBatch (t * testing.T ) {
327
332
exeCtx := utils .NewCancelableExecutionCtx ()
328
333
processor := NewBatchEventProcessor (WithQueueSize (100 ), WithFlushInterval (100 ),
329
- WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (& MockDispatcher { Events : NewInMemoryQueue (100 )} ))
334
+ WithQueue (NewInMemoryQueue (100 )), WithEventDispatcher (NewMockDispatcher (100 , false ) ))
330
335
processor .Start (exeCtx )
331
336
332
337
impression := BuildTestImpressionEvent ()
0 commit comments