From d702ca898b743197696b1f07e4b5b3f74583fcf9 Mon Sep 17 00:00:00 2001 From: Shuhei Nagasawa Date: Mon, 26 Feb 2024 20:21:45 +0900 Subject: [PATCH] add test --- .../src/test/java/acceptance/RetryIT.java | 60 +++++++++++++++++++ .../test/resources/acceptance/retry/helper.py | 5 ++ .../resources/acceptance/retry/retry-4.dig | 10 ++++ .../resources/acceptance/retry/retry-5.dig | 10 ++++ 4 files changed, 85 insertions(+) create mode 100644 digdag-tests/src/test/resources/acceptance/retry/helper.py create mode 100644 digdag-tests/src/test/resources/acceptance/retry/retry-4.dig create mode 100644 digdag-tests/src/test/resources/acceptance/retry/retry-5.dig diff --git a/digdag-tests/src/test/java/acceptance/RetryIT.java b/digdag-tests/src/test/java/acceptance/RetryIT.java index 3894e9c25a..5ff5aa8980 100644 --- a/digdag-tests/src/test/java/acceptance/RetryIT.java +++ b/digdag-tests/src/test/java/acceptance/RetryIT.java @@ -179,6 +179,58 @@ public void testRetry() assertThat(retry5Attempt.getParams().get("key", String.class), is("value")); } + @Test + public void testRetryWithStoredParams() + throws Exception + { + DigdagClient client = DigdagClient.builder() + .host(server.host()) + .port(server.port()) + .build(); + + // Push the project + pushRevision("acceptance/retry/retry-4.dig", "retry"); + + // Start the workflow + Id originalAttemptId; + { + CommandStatus startStatus = main("start", + "-c", config.toString(), + "-e", server.endpoint(), + "retry", "retry", + "--session", "now"); + assertThat(startStatus.errUtf8(), startStatus.code(), is(0)); + originalAttemptId = getAttemptId(startStatus); + } + + // Wait for the attempt to fail + assertThat(joinAttempt(client, originalAttemptId).getSuccess(), is(false)); + + assertOutputExists("4-1", true); + + // Push a new revision + pushRevision("acceptance/retry/retry-5.dig", "retry"); + + // Retry with the latest fixed revision & resume from + Id retry2; + { + CommandStatus retryStatus = main("retry", + "-c", config.toString(), + "-e", server.endpoint(), + "--latest-revision", + "--resume-from", "+step2+b", + String.valueOf(originalAttemptId)); + assertThat(retryStatus.errUtf8(), retryStatus.code(), is(0)); + retry2 = getAttemptId(retryStatus); + } + + // Wait for the attempt to success + assertThat(joinAttempt(client, retry2).getSuccess(), is(true)); + + assertOutputExists("5-1", false); // skipped + assertOutputContents("5-2b", "stored_value"); + } + private void pushRevision(String resourceName, String workflowName) throws IOException { @@ -213,6 +265,14 @@ private void assertOutputExists(String name, boolean exists) assertThat(Files.exists(root().resolve(name + ".out")), is(exists)); } + private void assertOutputContents(String name, String contents) + throws IOException + { + assertThat( + new String(Files.readAllBytes(root().resolve(name + ".out")), UTF_8).trim(), + is(contents)); + } + private Path root() { return folder.getRoot().toPath().toAbsolutePath(); diff --git a/digdag-tests/src/test/resources/acceptance/retry/helper.py b/digdag-tests/src/test/resources/acceptance/retry/helper.py new file mode 100644 index 0000000000..218aa500e4 --- /dev/null +++ b/digdag-tests/src/test/resources/acceptance/retry/helper.py @@ -0,0 +1,5 @@ +import digdag + + +def store_v(value): + digdag.env.store({'v': value}) diff --git a/digdag-tests/src/test/resources/acceptance/retry/retry-4.dig b/digdag-tests/src/test/resources/acceptance/retry/retry-4.dig new file mode 100644 index 0000000000..bb3d1a39a8 --- /dev/null +++ b/digdag-tests/src/test/resources/acceptance/retry/retry-4.dig @@ -0,0 +1,10 @@ ++step1: + sh>: touch ${outdir}/4-1.out ++step2: + +a: + if>: true + _do: + py>: helper.store_v + value: stored_value + +b: + fail>: step4b fail diff --git a/digdag-tests/src/test/resources/acceptance/retry/retry-5.dig b/digdag-tests/src/test/resources/acceptance/retry/retry-5.dig new file mode 100644 index 0000000000..ff90cf1a02 --- /dev/null +++ b/digdag-tests/src/test/resources/acceptance/retry/retry-5.dig @@ -0,0 +1,10 @@ ++step1: + sh>: touch ${outdir}/4-1.out ++step2: + +a: + if>: true + _do: + py>: helper.store_v + value: stored_value + +b: + sh>: echo ${value} > ${outdir}/4-2b.out