@@ -54,17 +54,6 @@ class SentryOkHttpEventListenerDelegationTest {
5454
5555 fun newCall (path : String ): Call =
5656 client.newCall(Request .Builder ().url(" http://localhost/$path " ).build())
57-
58- // The tests drive the listener by hand, so no call is ever really executed. canceled() branches
59- // on Call.isExecuted() to tell a cancel that precedes callStart() from one that follows the
60- // terminal event, so those cases need a Call that reports the state under test.
61- fun mockCall (path : String , isExecuted : Boolean ): Call {
62- val request = Request .Builder ().url(" http://localhost/$path " ).build()
63- return mock<Call >().also {
64- whenever(it.request()).thenReturn(request)
65- whenever(it.isExecuted()).thenReturn(isExecuted)
66- }
67- }
6857 }
6958
7059 private val fixture = Fixture ()
@@ -150,25 +139,34 @@ class SentryOkHttpEventListenerDelegationTest {
150139 }
151140
152141 @Test
153- fun `cancel before callStart binds the listener that callStart then reuses ` () {
142+ fun `cancel before callStart is not delegated and creates no listener ` () {
154143 val sut = fixture.getSut()
155- val call = fixture.mockCall(" 1" , isExecuted = false )
144+ val call = fixture.newCall(" 1" )
145+
146+ sut.canceled(call)
147+
148+ assertThat(fixture.listeners).isEmpty()
149+ }
150+
151+ @Test
152+ fun `a call canceled before callStart still gets a single listener when it starts` () {
153+ val sut = fixture.getSut()
154+ val call = fixture.newCall(" 1" )
156155
157156 sut.canceled(call)
158157 sut.callStart(call)
159- sut.dnsStart(call, " sentry.io" )
160- sut.callEnd(call)
158+ sut.callFailed(call, IOException (" Canceled" ))
161159
162160 assertThat(fixture.listeners).hasSize(1 )
163161 assertThat(fixture.listeners.single().received.map { it.first })
164- .containsExactly(" canceled " , " callStart" , " dnsStart " , " callEnd " )
162+ .containsExactly(" callStart" , " callFailed " )
165163 .inOrder()
166164 }
167165
168166 @Test
169167 fun `cancel after the terminal event is ignored` () {
170168 val sut = fixture.getSut()
171- val call = fixture.mockCall (" 1" , isExecuted = true )
169+ val call = fixture.newCall (" 1" )
172170
173171 sut.callStart(call)
174172 sut.callEnd(call)
@@ -183,7 +181,7 @@ class SentryOkHttpEventListenerDelegationTest {
183181 @Test
184182 fun `cancel after a failed call is ignored` () {
185183 val sut = fixture.getSut()
186- val call = fixture.mockCall (" 1" , isExecuted = true )
184+ val call = fixture.newCall (" 1" )
187185
188186 sut.callStart(call)
189187 sut.callFailed(call, IOException ())
@@ -198,7 +196,7 @@ class SentryOkHttpEventListenerDelegationTest {
198196 @Test
199197 fun `a single wrapped listener receives cancels outside of the call window` () {
200198 whenever(fixture.scopes.options).thenReturn(SentryOptions ())
201- val call = fixture.mockCall (" 1" , isExecuted = true )
199+ val call = fixture.newCall (" 1" )
202200 val listener = RecordingListener (call)
203201 val sut = SentryOkHttpEventListener (fixture.scopes, listener)
204202
0 commit comments