Skip to content

Commit 2b9f211

Browse files
committed
[a2a] Remove stress tests from regular a2a integration tests. Update a2a client according to PR comments
1 parent 8e860ba commit 2b9f211

File tree

3 files changed

+11
-75
lines changed

3 files changed

+11
-75
lines changed

a2a/a2a-client/src/commonMain/kotlin/ai/koog/a2a/client/A2AClient.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ import ai.koog.a2a.transport.ClientTransport
1515
import ai.koog.a2a.transport.Request
1616
import ai.koog.a2a.transport.Response
1717
import kotlinx.coroutines.flow.Flow
18-
import kotlin.concurrent.Volatile
18+
import kotlin.concurrent.atomics.AtomicReference
19+
import kotlin.concurrent.atomics.ExperimentalAtomicApi
1920

2021
/**
2122
* A2A client responsible for sending requests to A2A server.
2223
*/
24+
@OptIn(ExperimentalAtomicApi::class)
2325
public open class A2AClient(
2426
private val transport: ClientTransport,
2527
private val agentCardResolver: AgentCardResolver,
2628
) {
27-
@Volatile
28-
protected var agentCard: AgentCard? = null
29+
protected var agentCard: AtomicReference<AgentCard?> = AtomicReference(null)
2930

3031
/**
3132
* Performs initialization logic.
@@ -41,7 +42,7 @@ public open class A2AClient(
4142
*/
4243
public open suspend fun getAgentCard(): AgentCard {
4344
return agentCardResolver.resolve().also {
44-
agentCard = it
45+
agentCard.exchange(it)
4546
}
4647
}
4748

@@ -51,7 +52,7 @@ public open class A2AClient(
5152
* @throws [IllegalStateException] if it's not initialized
5253
*/
5354
public open fun cachedAgentCard(): AgentCard {
54-
return checkNotNull(agentCard) { "Agent card is not initialized." }
55+
return checkNotNull(agentCard.load()) { "Agent card is not initialized." }
5556
}
5657

5758
/**
@@ -64,12 +65,12 @@ public open class A2AClient(
6465
request: Request<Nothing?>,
6566
ctx: ClientCallContext = ClientCallContext.Default
6667
): Response<AgentCard> {
67-
check(getAgentCard().supportsAuthenticatedExtendedCard == true) {
68+
check(cachedAgentCard().supportsAuthenticatedExtendedCard == true) {
6869
"Agent card reports that authenticated extended agent card is not supported."
6970
}
7071

7172
return transport.getAuthenticatedExtendedAgentCard(request, ctx).also {
72-
agentCard = it.data
73+
agentCard.exchange(it.data)
7374
}
7475
}
7576

a2a/a2a-core/src/commonMain/kotlin/ai/koog/a2a/model/AgentCard.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public data class AgentCard(
110110
@JvmInline
111111
@Serializable
112112
public value class TransportProtocol(public val value: String) {
113-
@Suppress("MissingKDocForPublicAPI")
113+
/**
114+
* List of known transport protocols.
115+
*/
114116
public companion object {
115117
/**
116118
* JSON-RPC protocol.

a2a/a2a-server/src/jvmTest/kotlin/ai/koog/a2a/server/jsonrpc/A2AServerJsonRpcIntegrationTest.kt

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import kotlinx.coroutines.test.runTest
2626
import kotlinx.coroutines.withContext
2727
import org.junit.jupiter.api.AfterAll
2828
import org.junit.jupiter.api.BeforeAll
29-
import org.junit.jupiter.api.RepeatedTest
3029
import org.junit.jupiter.api.TestInstance
3130
import org.junit.jupiter.api.parallel.Execution
3231
import org.junit.jupiter.api.parallel.ExecutionMode
@@ -248,70 +247,4 @@ class A2AServerJsonRpcIntegrationTest : BaseA2AServerJsonRpcTest() {
248247
}
249248
}
250249
}
251-
252-
@RepeatedTest(300, name = "{currentRepetition}/{totalRepetitions}")
253-
fun `stress test cancel task`() = runTest(timeout = testTimeout) {
254-
val createTaskRequest = Request(
255-
data = MessageSendParams(
256-
message = Message(
257-
messageId = Uuid.Companion.random().toString(),
258-
role = Role.User,
259-
parts = listOf(
260-
TextPart("do cancelable task"),
261-
),
262-
contextId = "test-context"
263-
),
264-
),
265-
)
266-
267-
val taskId = (client.sendMessage(createTaskRequest).data as Task).id
268-
269-
val cancelTaskRequest = Request(
270-
data = TaskIdParams(
271-
id = taskId,
272-
)
273-
)
274-
275-
val response = client.cancelTask(cancelTaskRequest)
276-
277-
response.data should {
278-
it.id shouldBe taskId
279-
it.contextId shouldBe "test-context"
280-
it.status should {
281-
it.state shouldBe TaskState.Canceled
282-
it.message shouldNotBeNull {
283-
role shouldBe Role.Agent
284-
parts shouldBe listOf(TextPart("Task canceled"))
285-
}
286-
}
287-
}
288-
}
289-
290-
@RepeatedTest(300, name = "{currentRepetition}/{totalRepetitions}")
291-
fun `stress test send message`() = runTest(timeout = testTimeout) {
292-
val request = Request(
293-
data = MessageSendParams(
294-
message = Message(
295-
messageId = Uuid.Companion.random().toString(),
296-
role = Role.User,
297-
parts = listOf(
298-
TextPart("hello world"),
299-
),
300-
contextId = "test-context"
301-
),
302-
)
303-
)
304-
305-
val response = client.sendMessage(request)
306-
307-
response should {
308-
it.id shouldBe request.id
309-
310-
it.data.shouldBeInstanceOf<Message> {
311-
it.role shouldBe Role.Agent
312-
it.parts shouldBe listOf(TextPart("Hello World"))
313-
it.contextId shouldBe "test-context"
314-
}
315-
}
316-
}
317250
}

0 commit comments

Comments
 (0)