@@ -140,7 +140,7 @@ func getFactory() SplitFactory {
140140 impressionObserver , _ := strategy .NewImpressionObserver (500 )
141141 impressionsCounter := strategy .NewImpressionsCounter ()
142142 impressionsStrategy := strategy .NewOptimizedImpl (impressionObserver , impressionsCounter , telemetryStorage , false )
143- impressionManager := provisional .NewImpressionManager (impressionsStrategy )
143+ impressionManager := provisional .NewImpressionManager (impressionsStrategy ).( * provisional. ImpressionManagerImpl )
144144
145145 return SplitFactory {
146146 cfg : cfg ,
@@ -166,7 +166,7 @@ func getFactoryByFlagSets() SplitFactory {
166166 impressionObserver , _ := strategy .NewImpressionObserver (500 )
167167 impressionsCounter := strategy .NewImpressionsCounter ()
168168 impressionsStrategy := strategy .NewOptimizedImpl (impressionObserver , impressionsCounter , telemetryStorage , false )
169- impressionManager := provisional .NewImpressionManager (impressionsStrategy )
169+ impressionManager := provisional .NewImpressionManager (impressionsStrategy ).( * provisional. ImpressionManagerImpl )
170170
171171 return SplitFactory {
172172 cfg : cfg ,
@@ -473,7 +473,7 @@ func TestClientPanicking(t *testing.T) {
473473 impressionObserver , _ := strategy .NewImpressionObserver (500 )
474474 impressionsCounter := strategy .NewImpressionsCounter ()
475475 impressionsStrategy := strategy .NewOptimizedImpl (impressionObserver , impressionsCounter , telemetryMockedStorage , false )
476- impressionManager := provisional .NewImpressionManager (impressionsStrategy )
476+ impressionManager := provisional .NewImpressionManager (impressionsStrategy ).( * provisional. ImpressionManagerImpl )
477477
478478 factory := SplitFactory {
479479 cfg : cfg ,
@@ -650,7 +650,7 @@ func getClientForListener() SplitClient {
650650 impressionObserver , _ := strategy .NewImpressionObserver (500 )
651651 impressionsCounter := strategy .NewImpressionsCounter ()
652652 impressionsStrategy := strategy .NewOptimizedImpl (impressionObserver , impressionsCounter , telemetryMockedStorage , true )
653- impressionManager := provisional .NewImpressionManager (impressionsStrategy )
653+ impressionManager := provisional .NewImpressionManager (impressionsStrategy ).( * provisional. ImpressionManagerImpl )
654654
655655 factory := & SplitFactory {
656656 cfg : cfg ,
@@ -1372,7 +1372,7 @@ func TestClient(t *testing.T) {
13721372
13731373 impressionObserver , _ := strategy .NewImpressionObserver (500 )
13741374 impressionsStrategy := strategy .NewDebugImpl (impressionObserver , true )
1375- impressionManager := provisional .NewImpressionManager (impressionsStrategy )
1375+ impressionManager := provisional .NewImpressionManager (impressionsStrategy ).( * provisional. ImpressionManagerImpl )
13761376
13771377 factory := & SplitFactory {cfg : cfg , impressionManager : impressionManager }
13781378 client := SplitClient {
@@ -2114,6 +2114,105 @@ func TestClientDebug(t *testing.T) {
21142114 }
21152115}
21162116
2117+ func TestClientDebugWithImpressionsDisabledTrue (t * testing.T ) {
2118+ var isDestroyCalled = false
2119+ var splitsMock , _ = ioutil .ReadFile ("../../testdata/splits_mock_2.json" )
2120+
2121+ postChannel := make (chan string , 1 )
2122+ var count int64
2123+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2124+ switch r .URL .Path {
2125+ case "/splitChanges" :
2126+ fmt .Fprintln (w , string (splitsMock ))
2127+ return
2128+ case "/testImpressions/bulk" :
2129+ if r .Header .Get ("SplitSDKImpressionsMode" ) != commonsCfg .ImpressionsModeDebug {
2130+ t .Error ("Wrong header" )
2131+ }
2132+
2133+ if isDestroyCalled {
2134+ rBody , _ := ioutil .ReadAll (r .Body )
2135+ var dataInPost []map [string ]interface {}
2136+ err := json .Unmarshal (rBody , & dataInPost )
2137+ if err != nil {
2138+ t .Error (err )
2139+ return
2140+ }
2141+ if len (dataInPost ) != 1 {
2142+ t .Error ("It should send two impressions in optimized mode. Actual: " , len (dataInPost ))
2143+ }
2144+ if len (dataInPost [0 ]["i" ].([]interface {})) != 3 {
2145+ t .Error ("It should send only one impression per featureName" )
2146+ }
2147+ }
2148+
2149+ fmt .Fprintln (w , "ok" )
2150+ postChannel <- "finished"
2151+ case "/testImpressions/count" :
2152+ atomic .AddInt64 (& count , 1 )
2153+ case "/events/bulk" :
2154+ fmt .Fprintln (w , "ok" )
2155+ case "/segmentChanges" :
2156+ fallthrough
2157+ default :
2158+ fmt .Fprintln (w , "ok" )
2159+ }
2160+ }))
2161+ defer ts .Close ()
2162+
2163+ impTest := & ImpressionListenerTest {}
2164+ cfg := conf .Default ()
2165+ cfg .LabelsEnabled = true
2166+ cfg .Advanced .EventsURL = ts .URL
2167+ cfg .Advanced .SdkURL = ts .URL
2168+ cfg .Advanced .TelemetryServiceURL = ts .URL
2169+ cfg .Advanced .AuthServiceURL = ts .URL
2170+ cfg .Advanced .ImpressionListener = impTest
2171+ cfg .ImpressionsMode = "Debug"
2172+
2173+ factory , _ := NewSplitFactory ("test" , cfg )
2174+ client := factory .Client ()
2175+ client .BlockUntilReady (2 )
2176+
2177+ // Calls treatments to generate one valid impression
2178+ time .Sleep (300 * time .Millisecond ) // Let's wait until first call of recorders have finished
2179+ client .Treatment ("user1" , "DEMO_MURMUR2" , nil )
2180+ impL1 , _ := ilResult ["DEMO_MURMUR2" ].(map [string ]interface {})
2181+ if impL1 ["Pt" ].(int64 ) != 0 {
2182+ t .Error ("Pt should be 0" )
2183+ }
2184+ client .Treatment ("user1" , "DEMO_MURMUR2" , nil )
2185+ impL2 , _ := ilResult ["DEMO_MURMUR2" ].(map [string ]interface {})
2186+ if impL2 ["Pt" ] != impL1 ["Time" ] {
2187+ t .Error ("Pt should be equal to previos imp1" )
2188+ }
2189+ client .Treatments ("user1" , []string {"DEMO_MURMUR2" }, nil )
2190+ impL3 , _ := ilResult ["DEMO_MURMUR2" ].(map [string ]interface {})
2191+ if impL3 ["Pt" ] != impL2 ["Time" ] {
2192+ t .Error ("Pt should be equal to previos imp2" )
2193+ }
2194+
2195+ client .Treatment ("user1" , "IMPRESSION_TOGGLE_FLAG" , nil )
2196+ impL4 , _ := ilResult ["IMPRESSION_TOGGLE_FLAG" ].(map [string ]interface {})
2197+ if impL4 ["Pt" ].(int64 ) != 0 {
2198+ t .Error ("Pt should be 0" )
2199+ }
2200+
2201+ isDestroyCalled = true
2202+ client .Destroy ()
2203+
2204+ select {
2205+ case <- postChannel :
2206+ if atomic .LoadInt64 (& count ) != 1 {
2207+ t .Error ("Impression Count should be 1. Actual: " , atomic .LoadInt64 (& count ))
2208+ }
2209+ return
2210+ case <- time .After (4 * time .Second ):
2211+ t .Error ("The test couldn't send impressions to check headers" )
2212+ return
2213+ }
2214+ }
2215+
21172216func TestUnsupportedMatcherAndSemver (t * testing.T ) {
21182217 var isDestroyCalled = false
21192218 var splitsMock , _ = ioutil .ReadFile ("../../testdata/splits_mock_3.json" )
@@ -2357,7 +2456,7 @@ func TestTelemetryMemory(t *testing.T) {
23572456 t .Error ("It should queue one impression" )
23582457 }
23592458 if dataInPost .ImpressionsDeduped != 1 {
2360- t .Error ("It should dedupe one impression" )
2459+ t .Error ("It should dedupe one impression. " , dataInPost . ImpressionsDeduped )
23612460 }
23622461 if dataInPost .EventsQueued != 1 {
23632462 t .Error ("It should queue one event" )
0 commit comments