Skip to content

Commit

Permalink
fix(samples): adds retry to TranslateCreateDatasetTest (#513)
Browse files Browse the repository at this point in the history
* fix(samples): adds retry to TranslateCreateDatasetTest
  • Loading branch information
telpirion authored and anguillanneuf committed Dec 5, 2022
1 parent 81bc043 commit 255b385
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions automl/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
<version>1.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
<version>1.94.0</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<!-- [END_EXCLUDE] -->
</dependencies>
<!-- [END automl_install_with_bom] -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertNotNull;

import com.google.cloud.testing.junit4.MultipleAttemptsRule;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
Expand All @@ -27,6 +28,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -39,7 +41,7 @@ public class TranslateCreateDatasetTest {
private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;
private String datasetId;
private String got;

private static void requireEnvVar(String varName) {
assertNotNull(
Expand All @@ -63,11 +65,15 @@ public void setUp() {

@After
public void tearDown() throws InterruptedException, ExecutionException, IOException {
String datasetId = got.split("Dataset id: ")[1].split("\n")[0];

// Delete the created dataset
DeleteDataset.deleteDataset(PROJECT_ID, datasetId);
System.setOut(originalPrintStream);
}

@Rule public MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);

@Test
public void testCreateDataset() throws IOException, ExecutionException, InterruptedException {
// Create a random dataset name with a length of 32 characters (max allowed by AutoML)
Expand All @@ -77,8 +83,7 @@ public void testCreateDataset() throws IOException, ExecutionException, Interrup
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
TranslateCreateDataset.createDataset(PROJECT_ID, datasetName);

String got = bout.toString();
got = bout.toString();
assertThat(got).contains("Dataset id:");
datasetId = got.split("Dataset id: ")[1].split("\n")[0];
}
}

0 comments on commit 255b385

Please sign in to comment.