Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt tests to send status #345

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ abstract class BaseCancelInvocationTest {
val cancelTestClient = CancelTestRunnerClient.fromIngress(ingressClient, key)
val blockingServiceClient = CancelTestBlockingServiceClient.fromIngress(ingressClient, key)

val id = cancelTestClient.send().startTest(blockingOperation)
val id = cancelTestClient.send().startTest(blockingOperation).invocationId

val awakeableHolderClient = AwakeableHolderClient.fromIngress(ingressClient, "cancel")

Expand Down
41 changes: 13 additions & 28 deletions tests/src/test/kotlin/dev/restate/e2e/WorkflowAPITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dev.restate.e2e.utils.InjectIngressClient
import dev.restate.e2e.utils.RestateDeployer
import dev.restate.e2e.utils.RestateDeployerExtension
import dev.restate.sdk.client.IngressClient
import dev.restate.sdk.client.SendResponse.SendStatus
import java.util.*
import my.restate.e2e.services.WorkflowAPIBlockAndWaitClient
import org.assertj.core.api.Assertions.assertThat
Expand All @@ -27,7 +28,7 @@ import org.junit.jupiter.api.parallel.Execution
import org.junit.jupiter.api.parallel.ExecutionMode

@Tag("always-suspending")
class JavaWorkflowAPITest {
class JavaWorkflowAPITest : BaseWorkflowAPITest() {

companion object {
@RegisterExtension
Expand All @@ -37,32 +38,10 @@ class JavaWorkflowAPITest {
.withServiceEndpoint(Containers.JAVA_WORKFLOW_SERVICE_SPEC)
.build())
}

@Test
@DisplayName("Set and resolve durable promise leads to completion")
@Execution(ExecutionMode.CONCURRENT)
fun setAndResolve(@InjectIngressClient ingressClient: IngressClient) {
val client =
WorkflowAPIBlockAndWaitClient.fromIngress(ingressClient, UUID.randomUUID().toString())
val handle = client.submit("Francesco")

// Wait state is set
await untilCallTo { client.getState() } matches { it!!.isPresent }

client.unblock("Till")

assertThat(handle.attach()).isEqualTo("Till")

// Can call get output again
assertThat(handle.output).isEqualTo("Till")

// Re-submit should have no effect
assertThat(client.submit("Francesco").output).isEqualTo("Till")
}
}

@Tag("always-suspending")
class NodeWorkflowAPITest {
class NodeWorkflowAPITest : BaseWorkflowAPITest() {

companion object {
@RegisterExtension
Expand All @@ -72,27 +51,33 @@ class NodeWorkflowAPITest {
.withServiceEndpoint(Containers.NODE_WORKFLOW_SERVICE_SPEC)
.build())
}
}

abstract class BaseWorkflowAPITest {
@Test
@DisplayName("Set and resolve durable promise leads to completion")
@Execution(ExecutionMode.CONCURRENT)
fun setAndResolve(@InjectIngressClient ingressClient: IngressClient) {
val client =
WorkflowAPIBlockAndWaitClient.fromIngress(ingressClient, UUID.randomUUID().toString())

val handle = client.submit("Francesco")
val sendResponse = client.submit("Francesco")
assertThat(sendResponse.status).isEqualTo(SendStatus.ACCEPTED)

// Wait state is set
await untilCallTo { client.getState() } matches { it!!.isPresent }

client.unblock("Till")

assertThat(handle.attach()).isEqualTo("Till")
assertThat(client.workflowHandle().attach()).isEqualTo("Till")

// Can call get output again
assertThat(handle.output).isEqualTo("Till")
assertThat(client.workflowHandle().output).isEqualTo("Till")

// Re-submit should have no effect
assertThat(client.submit("Francesco").output).isEqualTo("Till")
val secondSendResponse = client.submit("Francesco")
assertThat(secondSendResponse.status).isEqualTo(SendStatus.PREVIOUSLY_ACCEPTED)
assertThat(secondSendResponse.invocationId).isEqualTo(sendResponse.invocationId)
assertThat(client.workflowHandle().output).isEqualTo("Till")
}
}
12 changes: 9 additions & 3 deletions tests/src/test/kotlin/dev/restate/e2e/runtime/IngressTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dev.restate.sdk.JsonSerdes
import dev.restate.sdk.client.CallRequestOptions
import dev.restate.sdk.client.IngressClient
import dev.restate.sdk.client.IngressException
import dev.restate.sdk.client.SendResponse.SendStatus
import java.net.URL
import java.util.*
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -139,11 +140,15 @@ class IngressTest {
val counterClient = CounterClient.fromIngress(ingressClient, counterRandomName)

// Send request twice
val firstInvocationId = counterClient.send().add(2, requestOptions)
val secondInvocationId = counterClient.send().add(2, requestOptions)
val firstInvocationSendStatus = counterClient.send().add(2, requestOptions)
assertThat(firstInvocationSendStatus.status).isEqualTo(SendStatus.ACCEPTED)
val secondInvocationSendStatus = counterClient.send().add(2, requestOptions)
assertThat(secondInvocationSendStatus.status).isEqualTo(SendStatus.PREVIOUSLY_ACCEPTED)

// IDs should be the same
assertThat(firstInvocationId).startsWith("inv").isEqualTo(secondInvocationId)
assertThat(firstInvocationSendStatus.invocationId)
.startsWith("inv")
.isEqualTo(secondInvocationSendStatus.invocationId)

// Wait for get
await untilAsserted { assertThat(counterClient.get()).isEqualTo(2) }
Expand All @@ -169,6 +174,7 @@ class IngressTest {
echoClient
.send()
.blockThenEcho(awakeableKey, CallRequestOptions().withIdempotency(myIdempotencyId))
.invocationId
val invocationHandle = ingressClient.invocationHandle(invocationId, JsonSerdes.STRING)

// Attach to request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class KillTestInvocationTest {

@Test
fun kill(@InjectIngressClient ingressClient: IngressClient, @InjectMetaURL metaURL: URL) {
val id = KillTestRunnerClient.fromIngress(ingressClient).send().startCallTree()
val id = KillTestRunnerClient.fromIngress(ingressClient).send().startCallTree().invocationId
val awakeableHolderClient = AwakeableHolderClient.fromIngress(ingressClient, "kill")

// Await until AwakeableHolder has an awakeable and then complete it.
Expand Down