@@ -2,6 +2,7 @@ package eppoclient
2
2
3
3
import (
4
4
"testing"
5
+ "time"
5
6
6
7
"github.com/stretchr/testify/assert"
7
8
"github.com/stretchr/testify/mock"
@@ -15,15 +16,15 @@ var (
15
16
16
17
func Test_AssignBlankExperiment (t * testing.T ) {
17
18
var mockLogger = new (mockLogger )
18
- client := newEppoClient (newConfigurationStore (configuration {} ), nil , nil , mockLogger , applicationLogger )
19
+ client := newEppoClient (newConfigurationStore (), nil , nil , mockLogger , applicationLogger )
19
20
20
21
_ , err := client .GetStringAssignment ("" , "subject-1" , Attributes {}, "" )
21
22
assert .Error (t , err )
22
23
}
23
24
24
25
func Test_AssignBlankSubject (t * testing.T ) {
25
26
var mockLogger = new (mockLogger )
26
- client := newEppoClient (newConfigurationStore (configuration {} ), nil , nil , mockLogger , applicationLogger )
27
+ client := newEppoClient (newConfigurationStore (), nil , nil , mockLogger , applicationLogger )
27
28
28
29
_ , err := client .GetStringAssignment ("experiment-1" , "" , Attributes {}, "" )
29
30
assert .Error (t , err )
@@ -96,7 +97,7 @@ func Test_LogAssignment(t *testing.T) {
96
97
},
97
98
}
98
99
99
- client := newEppoClient (newConfigurationStore (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
100
+ client := newEppoClient (newConfigurationStoreWithConfig (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
100
101
101
102
assignment , err := client .GetStringAssignment ("experiment-key-1" , "user-1" , Attributes {}, "" )
102
103
expected := "control"
@@ -141,7 +142,7 @@ func Test_client_loggerIsCalledWithProperBanditEvent(t *testing.T) {
141
142
},
142
143
}
143
144
144
- client := newEppoClient (newConfigurationStore (configuration {flags : flags , bandits : bandits }), nil , nil , logger , applicationLogger )
145
+ client := newEppoClient (newConfigurationStoreWithConfig (configuration {flags : flags , bandits : bandits }), nil , nil , logger , applicationLogger )
145
146
actions := map [string ]ContextAttributes {
146
147
"action1" : {},
147
148
}
@@ -194,7 +195,7 @@ func Test_GetStringAssignmentHandlesLoggingPanic(t *testing.T) {
194
195
},
195
196
}}
196
197
197
- client := newEppoClient (newConfigurationStore (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
198
+ client := newEppoClient (newConfigurationStoreWithConfig (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
198
199
199
200
assignment , err := client .GetStringAssignment ("experiment-key-1" , "user-1" , Attributes {}, "" )
200
201
expected := "control"
@@ -236,7 +237,7 @@ func Test_client_handlesBanditLoggerPanic(t *testing.T) {
236
237
},
237
238
}
238
239
239
- client := newEppoClient (newConfigurationStore (configuration {flags : flags , bandits : bandits }), nil , nil , logger , applicationLogger )
240
+ client := newEppoClient (newConfigurationStoreWithConfig (configuration {flags : flags , bandits : bandits }), nil , nil , logger , applicationLogger )
240
241
actions := map [string ]ContextAttributes {
241
242
"action1" : {},
242
243
}
@@ -278,7 +279,7 @@ func Test_client_correctActionIsReturnedIfBanditLoggerPanics(t *testing.T) {
278
279
},
279
280
}
280
281
281
- client := newEppoClient (newConfigurationStore (configuration {flags : flags , bandits : bandits }), nil , nil , logger , applicationLogger )
282
+ client := newEppoClient (newConfigurationStoreWithConfig (configuration {flags : flags , bandits : bandits }), nil , nil , logger , applicationLogger )
282
283
actions := map [string ]ContextAttributes {
283
284
"action1" : {},
284
285
}
@@ -290,3 +291,39 @@ func Test_client_correctActionIsReturnedIfBanditLoggerPanics(t *testing.T) {
290
291
Action : & expectedAction ,
291
292
}, result )
292
293
}
294
+
295
+ func Test_Initialized_timeout (t * testing.T ) {
296
+ var mockLogger = new (mockLogger )
297
+ client := newEppoClient (newConfigurationStore (), nil , nil , mockLogger , applicationLogger )
298
+
299
+ timedOut := false
300
+ select {
301
+ case <- client .Initialized ():
302
+ timedOut = false
303
+ case <- time .After (1 * time .Millisecond ):
304
+ timedOut = true
305
+ }
306
+
307
+ assert .True (t , timedOut )
308
+ }
309
+
310
+ func Test_Initialized_success (t * testing.T ) {
311
+ var mockLogger = new (mockLogger )
312
+ configurationStore := newConfigurationStore ()
313
+ client := newEppoClient (configurationStore , nil , nil , mockLogger , applicationLogger )
314
+
315
+ go func () {
316
+ <- time .After (1 * time .Microsecond )
317
+ configurationStore .setConfiguration (configuration {})
318
+ }()
319
+
320
+ timedOut := false
321
+ select {
322
+ case <- client .Initialized ():
323
+ timedOut = false
324
+ case <- time .After (1 * time .Millisecond ):
325
+ timedOut = true
326
+ }
327
+
328
+ assert .False (t , timedOut )
329
+ }
0 commit comments