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

[test] fix flaky test for testBatchWriteGeneratorTag. #3546

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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 @@ -70,19 +70,13 @@ public void testBatchWriteGeneratorTag() throws Exception {
SnapshotManager snapshotManager = table.newSnapshotReader().snapshotManager();
TagManager tagManager = table.tagManager();

// Generate tag name
String prefix = "batch-write-";
Instant instant =
Instant.ofEpochMilli(
Objects.requireNonNull(snapshotManager.latestSnapshot()).timeMillis());
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
String tagName = prefix + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));

// No tag is generated before the finish method
assertThat(table.tagManager().tagCount()).isEqualTo(0);
committerOperator.finish();
// After the finish method, a tag is generated
assertThat(table.tagManager().tagCount()).isEqualTo(1);
// Get tagName from tagManager.
String tagName = tagManager.allTagNames().get(0);
// The tag is consistent with the latest snapshot
assertThat(tagManager.taggedSnapshot(tagName)).isEqualTo(snapshotManager.latestSnapshot());

Expand All @@ -98,7 +92,16 @@ public void testBatchWriteGeneratorTag() throws Exception {
// note that this tag has the same name with previous tag
// so the previous tag will be deleted
committerOperator.finish();

// If tagName does not exist, it happened across the day.
if (!tagManager.tagExists(tagName)) {
// Generate tag name
String prefix = "batch-write-";
Instant instant =
Instant.ofEpochMilli(
Objects.requireNonNull(snapshotManager.latestSnapshot()).timeMillis());
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
tagName = prefix + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
assertThat(tagManager.allTagNames()).containsOnly("many-tags-test2", tagName);
}

Expand Down
Loading