@@ -138,6 +138,16 @@ class SentryOkHttpEventListenerDelegationTest {
138138 .inOrder()
139139 }
140140
141+ /* *
142+ * Deliberate deviation from the [okhttp3.EventListener.Factory] contract: OkHttp would give the
143+ * listener of this call the cancellation, we do not.
144+ *
145+ * A cancel can arrive before [okhttp3.EventListener.callStart] and after the terminal event,
146+ * while we can only bind a wrapped listener to a call between the two. Creating a listener here
147+ * would either give the call a second listener, or leave an entry that no terminal event can ever
148+ * remove, because a call that is canceled and never executed gets no terminal event at all. See
149+ * the KDoc of [SentryOkHttpEventListener] for the full reasoning.
150+ */
141151 @Test
142152 fun `cancel before callStart is not delegated and creates no listener` () {
143153 val sut = fixture.getSut()
@@ -148,6 +158,7 @@ class SentryOkHttpEventListenerDelegationTest {
148158 assertThat(fixture.listeners).isEmpty()
149159 }
150160
161+ /* * The deviation costs only the cancel itself: the call still gets exactly one listener. */
151162 @Test
152163 fun `a call canceled before callStart still gets a single listener when it starts` () {
153164 val sut = fixture.getSut()
@@ -163,6 +174,10 @@ class SentryOkHttpEventListenerDelegationTest {
163174 .inOrder()
164175 }
165176
177+ /* *
178+ * Same deviation, on the other edge. [okhttp3.Call.cancel] is a documented no-op for a request
179+ * that is already complete, so there is nothing to report.
180+ */
166181 @Test
167182 fun `cancel after the terminal event is ignored` () {
168183 val sut = fixture.getSut()
@@ -178,6 +193,7 @@ class SentryOkHttpEventListenerDelegationTest {
178193 .inOrder()
179194 }
180195
196+ /* * As above, with [okhttp3.EventListener.callFailed] as the terminal event. */
181197 @Test
182198 fun `cancel after a failed call is ignored` () {
183199 val sut = fixture.getSut()
@@ -193,6 +209,10 @@ class SentryOkHttpEventListenerDelegationTest {
193209 .inOrder()
194210 }
195211
212+ /* *
213+ * No deviation for a single wrapped instance: it is shared by every call anyway, the same as
214+ * OkHttp's own `EventListener.asFactory()`, so it outlives the window and gets every cancel.
215+ */
196216 @Test
197217 fun `a single wrapped listener receives cancels outside of the call window` () {
198218 whenever(fixture.scopes.options).thenReturn(SentryOptions ())
0 commit comments