Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
snagasawa committed Feb 26, 2024
1 parent 6aa7cb9 commit d702ca8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
60 changes: 60 additions & 0 deletions digdag-tests/src/test/java/acceptance/RetryIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions digdag-tests/src/test/resources/acceptance/retry/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import digdag


def store_v(value):
digdag.env.store({'v': value})
10 changes: 10 additions & 0 deletions digdag-tests/src/test/resources/acceptance/retry/retry-4.dig
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions digdag-tests/src/test/resources/acceptance/retry/retry-5.dig
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d702ca8

Please sign in to comment.