@@ -2,6 +2,7 @@ package eppoclient
22
33import (
44 "testing"
5+ "time"
56
67 "github.com/stretchr/testify/assert"
78 "github.com/stretchr/testify/mock"
@@ -15,15 +16,15 @@ var (
1516
1617func Test_AssignBlankExperiment (t * testing.T ) {
1718 var mockLogger = new (mockLogger )
18- client := newEppoClient (newConfigurationStore (configuration {} ), nil , nil , mockLogger , applicationLogger )
19+ client := newEppoClient (newConfigurationStore (), nil , nil , mockLogger , applicationLogger )
1920
2021 _ , err := client .GetStringAssignment ("" , "subject-1" , Attributes {}, "" )
2122 assert .Error (t , err )
2223}
2324
2425func Test_AssignBlankSubject (t * testing.T ) {
2526 var mockLogger = new (mockLogger )
26- client := newEppoClient (newConfigurationStore (configuration {} ), nil , nil , mockLogger , applicationLogger )
27+ client := newEppoClient (newConfigurationStore (), nil , nil , mockLogger , applicationLogger )
2728
2829 _ , err := client .GetStringAssignment ("experiment-1" , "" , Attributes {}, "" )
2930 assert .Error (t , err )
@@ -96,7 +97,7 @@ func Test_LogAssignment(t *testing.T) {
9697 },
9798 }
9899
99- client := newEppoClient (newConfigurationStore (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
100+ client := newEppoClient (newConfigurationStoreWithConfig (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
100101
101102 assignment , err := client .GetStringAssignment ("experiment-key-1" , "user-1" , Attributes {}, "" )
102103 expected := "control"
@@ -141,7 +142,7 @@ func Test_client_loggerIsCalledWithProperBanditEvent(t *testing.T) {
141142 },
142143 }
143144
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 )
145146 actions := map [string ]ContextAttributes {
146147 "action1" : {},
147148 }
@@ -194,7 +195,7 @@ func Test_GetStringAssignmentHandlesLoggingPanic(t *testing.T) {
194195 },
195196 }}
196197
197- client := newEppoClient (newConfigurationStore (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
198+ client := newEppoClient (newConfigurationStoreWithConfig (configuration {flags : config }), nil , nil , mockLogger , applicationLogger )
198199
199200 assignment , err := client .GetStringAssignment ("experiment-key-1" , "user-1" , Attributes {}, "" )
200201 expected := "control"
@@ -236,7 +237,7 @@ func Test_client_handlesBanditLoggerPanic(t *testing.T) {
236237 },
237238 }
238239
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 )
240241 actions := map [string ]ContextAttributes {
241242 "action1" : {},
242243 }
@@ -278,7 +279,7 @@ func Test_client_correctActionIsReturnedIfBanditLoggerPanics(t *testing.T) {
278279 },
279280 }
280281
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 )
282283 actions := map [string ]ContextAttributes {
283284 "action1" : {},
284285 }
@@ -290,3 +291,39 @@ func Test_client_correctActionIsReturnedIfBanditLoggerPanics(t *testing.T) {
290291 Action : & expectedAction ,
291292 }, result )
292293}
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