@@ -59,9 +59,98 @@ class DiagnosticsTest {
59
59
assertEquals(Gson ().toJson(options.getLoggingCopy()), diagnosticsEvent!! .eventMetadata!! [" statsigOptions" ])
60
60
}
61
61
62
+ @Test
63
+ fun testCoreAPI () = runBlocking {
64
+ val downloadConfigSpecsResponseWithSampling = StringBuilder (downloadConfigSpecsResponse).insert(downloadConfigSpecsResponse.length - 2 , " ,\n \" diagnostics\" : {\" initialize\" : \" 0\" , \" api_call\" : \" 10000\" }" ).toString()
65
+ setupWebServer(downloadConfigSpecsResponseWithSampling)
66
+ driver.initializeAsync(" secret-testcase" , options).get()
67
+ val user = StatsigUser (" testUser" )
68
+ driver.checkGate(user, " always_on_gate" )
69
+ driver.getConfig(user, " test_config" )
70
+ driver.getExperiment(user, " sample_experiment" )
71
+ driver.getLayer(user, " a_layer" )
72
+ driver.shutdown()
73
+ val events = TestUtil .captureEvents(eventLogInputCompletable)
74
+ val diagnosticsEvent = events.find { it.eventName == " statsig::diagnostics" }
75
+ val markers: List <Marker > = gson.fromJson(diagnosticsEvent!! .eventMetadata!! [" markers" ], object : TypeToken <List <Marker >>() {}.type)
76
+ assertEquals(8 , markers.size)
77
+ verifyMarker(
78
+ markers[0 ],
79
+ Marker (
80
+ markerID = " CHECK_GATE_0" ,
81
+ action = ActionType .START ,
82
+ configName = " always_on_gate" ,
83
+ key = KeyType .CHECK_GATE ,
84
+ ),
85
+ )
86
+ verifyMarker(
87
+ markers[1 ],
88
+ Marker (
89
+ markerID = " CHECK_GATE_0" ,
90
+ action = ActionType .END ,
91
+ configName = " always_on_gate" ,
92
+ key = KeyType .CHECK_GATE ,
93
+ ),
94
+ )
95
+ verifyMarker(
96
+ markers[2 ],
97
+ Marker (
98
+ markerID = " GET_CONFIG_2" ,
99
+ action = ActionType .START ,
100
+ configName = " test_config" ,
101
+ key = KeyType .GET_CONFIG ,
102
+ ),
103
+ )
104
+ verifyMarker(
105
+ markers[3 ],
106
+ Marker (
107
+ markerID = " GET_CONFIG_2" ,
108
+ action = ActionType .END ,
109
+ configName = " test_config" ,
110
+ key = KeyType .GET_CONFIG ,
111
+ ),
112
+ )
113
+ verifyMarker(
114
+ markers[4 ],
115
+ Marker (
116
+ markerID = " GET_EXPERIMENT_4" ,
117
+ action = ActionType .START ,
118
+ configName = " sample_experiment" ,
119
+ key = KeyType .GET_EXPERIMENT ,
120
+ ),
121
+ )
122
+ verifyMarker(
123
+ markers[5 ],
124
+ Marker (
125
+ markerID = " GET_EXPERIMENT_4" ,
126
+ action = ActionType .END ,
127
+ configName = " sample_experiment" ,
128
+ key = KeyType .GET_EXPERIMENT ,
129
+ ),
130
+ )
131
+ verifyMarker(
132
+ markers[6 ],
133
+ Marker (
134
+ markerID = " GET_LAYER_6" ,
135
+ action = ActionType .START ,
136
+ configName = " a_layer" ,
137
+ key = KeyType .GET_LAYER ,
138
+ ),
139
+ )
140
+ verifyMarker(
141
+ markers[7 ],
142
+ Marker (
143
+ markerID = " GET_LAYER_6" ,
144
+ action = ActionType .END ,
145
+ configName = " a_layer" ,
146
+ key = KeyType .GET_LAYER ,
147
+ ),
148
+ )
149
+ }
150
+
62
151
@Test
63
152
fun testSamping () = runBlocking {
64
- val downloadConfigSpecsResponseWithSampling = StringBuilder (downloadConfigSpecsResponse).insert(downloadConfigSpecsResponse.length - 2 , " ,\n \" diagnostics\" : {\" initialize\" : \" 0\" }" ).toString()
153
+ val downloadConfigSpecsResponseWithSampling = StringBuilder (downloadConfigSpecsResponse).insert(downloadConfigSpecsResponse.length - 2 , " ,\n \" diagnostics\" : {\" initialize\" : \" 0\" , \" api_call \" : \" 0 \" }" ).toString()
65
154
setupWebServer(downloadConfigSpecsResponseWithSampling)
66
155
driver.initializeAsync(" secret-testcase" , options).get()
67
156
driver.shutdown()
@@ -99,5 +188,7 @@ class DiagnosticsTest {
99
188
Assert .assertEquals(expected.key, actual.key)
100
189
Assert .assertEquals(expected.action, actual.action)
101
190
Assert .assertEquals(expected.step, actual.step)
191
+ Assert .assertEquals(expected.configName, actual.configName)
192
+ Assert .assertEquals(expected.markerID, actual.markerID)
102
193
}
103
194
}
0 commit comments