You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to integrate allure report with my okhttp3-sse SSE tests.
Particularly, I use EventSourceListener to asyncronously collect events to then process them with different asserts.
I tried adding AllureOkHttp3 interceptor, but this completely breaks the code, looks like it consumes the events and they do not reach the onEvent in the listener.
Also, without this integration, any methods annotated with @Step annotation, that are executed within the listener, are not present in the report.
I am not sure if this is a bug, but maybe you could point me in a direction on how I can make sure my @Step methods are included in the report (like some mumbo-jumbo with AspectJ).
Here's my SSEClient class:
package.tms.utilsimporttms.api.ConnectionApiimporttms.api.ConnectionApi.becomeOnlineimporttms.api.SSEApiimporttms.api.SSEApi.SUBSCRIBEimporttms.constants.General.BRAINSimporttms.steps.sse.SSEEventNameimporttms.utils.LatchManager.latchimporttms.utils.debug.DebugLoggerimportio.qameta.allure.okhttp3.AllureOkHttp3importokhttp3.OkHttpClientimportokhttp3.Requestimportokhttp3.Responseimportokhttp3.sse.EventSourceimportokhttp3.sse.EventSourceListenerimportokhttp3.sse.EventSourcesimportorg.apache.http.HttpHeaders.AUTHORIZATIONimportjava.net.SocketExceptionimportjava.util.concurrent.CountDownLatchimportjava.util.concurrent.TimeUnitclassSSEClient {
privateval params =OkHttpClient.Builder()
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.addInterceptor(AllureOkHttp3())
.build()
privatelateinitvar eventSource:EventSourcefunlisten(
token:String,
onConnect: () ->Unit = {},
onEvent: (type: String?, data: String?) ->Unit,
stopAfter:SSEEventName? = null,
timeout:Long = 10,
eventsCount:Int = 10,
) {
latch =CountDownLatch(eventsCount)
eventSource =EventSources.createFactory(params)
.newEventSource(buildRequest(token), createListener(token, onConnect, onEvent, stopAfter))
try {
if (!latch.await(timeout, TimeUnit.SECONDS)) {
if (DebugLogger.sseLoggingIsActive) println("Async timeout reached, disconnected")
}
} finally {
eventSource.cancel()
}
}
privatefunbuildRequest(token:String): Request {
returnRequest.Builder().url(BRAINS+SUBSCRIBE).addHeader(AUTHORIZATION, token).build()
}
privatefunpong(token:String) {
SSEApi.pong(token)
ConnectionApi.ping(token)
if (DebugLogger.sseLoggingIsActive) println("pong")
}
privatefuncreateListener(
token:String,
trigger: () ->Unit = {},
onEventWrap: (type: String?, data: String?) ->Unit,
stopAfter:SSEEventName? = null,
onFailure: () ->Unit = {},
onClosed: () ->Unit = {},
) =object:EventSourceListener() {
overridefunonOpen(eventSource:EventSource, response:Response) {
becomeOnline(token)
trigger()
}
overridefunonEvent(eventSource:EventSource, id:String?, type:String?, data:String) {
if (DebugLogger.sseLoggingIsActive) println("Received event: $type : $data")
if (type =="ping") pong(token)
if (type !="ping") {
onEventWrap(type, data)
if (stopAfter ==null) latch.countDown()
}
if (type == stopAfter?.event) {
eventSource.cancel()
repeat(latch.count.toInt()) { latch.countDown() }
}
}
overridefunonFailure(eventSource:EventSource, t:Throwable?, response:Response?) {
if (DebugLogger.sseLoggingIsActive) println(t)
onFailure()
if (t !=null&& t !isSocketException) throw t
}
overridefunonClosed(eventSource:EventSource) {
if (DebugLogger.sseLoggingIsActive) println("Closed connection")
onClosed()
}
}
}
```
![Screenshot from 2024-04-1919-08-01](https://github.com/allure-framework/allure-java/assets/111231219/00d66723-ed6a-4daa-8cfd-ca91e2beb634)
### WhatAllureIntegration are you using?
allure-okhttp3
### What version of AllureIntegration you are using?2.27.0
### What version of AllureReport you are using?2.27.0
### Code of Conduct- [X] I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
I tried running the tests separately and in a row (within a test class).
Turned out, the first test I launch has all the steps inside the listener correctly, while every other consequential test does not.
To my understanding, this has to do something with how Step Lyfecycle is determined.
Is there any way to "reset" Step lifycycle after every test explicitely? Or maybe any other way to mitigate this issue.
Please let me know if any additional information is needed.
And here I launch the test isolated, the steps are present:
What happened?
Hi!
I am trying to integrate allure report with my okhttp3-sse SSE tests.
Particularly, I use EventSourceListener to asyncronously collect events to then process them with different asserts.
I tried adding
AllureOkHttp3
interceptor, but this completely breaks the code, looks like it consumes the events and they do not reach theonEvent
in the listener.Also, without this integration, any methods annotated with
@Step
annotation, that are executed within the listener, are not present in the report.I am not sure if this is a bug, but maybe you could point me in a direction on how I can make sure my
@Step
methods are included in the report (like some mumbo-jumbo with AspectJ).Here's my SSEClient class:
The text was updated successfully, but these errors were encountered: