-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix Flaky DLP tests #2447
Fix Flaky DLP tests #2447
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,13 @@ | |
import static org.hamcrest.core.StringContains.containsString; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import com.google.cloud.dlp.v2.DlpServiceClient; | ||
import com.google.privacy.dlp.v2.CancelDlpJobRequest; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
@@ -100,31 +103,59 @@ public void testInspectImageFile() { | |
|
||
@Test | ||
public void testInspectGcsFile() throws InterruptedException, ExecutionException, IOException { | ||
|
||
InspectGcsFile.inspectGcsFile(PROJECT_ID, GCS_PATH, TOPIC_ID, SUBSCRIPTION_ID); | ||
// Await job creation | ||
TimeUnit.SECONDS.sleep(3); | ||
|
||
String output = bout.toString(); | ||
assertThat(output, containsString("Info type: PHONE_NUMBER")); | ||
assertThat(output, containsString("Info type: EMAIL_ADDRESS")); | ||
assertThat(output, containsString("Job created: ")); | ||
|
||
// Cancelling the job early to conserve quota | ||
String jobId = output.split("Job created: ")[1].split("\n")[0]; | ||
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build(); | ||
try (DlpServiceClient client = DlpServiceClient.create()) { | ||
client.cancelDlpJob(request); | ||
} | ||
} | ||
|
||
@Test | ||
public void testInspectDatastoreEntity() | ||
throws InterruptedException, ExecutionException, IOException { | ||
|
||
InspectDatastoreEntity.insepctDatastoreEntity( | ||
PROJECT_ID, datastoreNamespace, datastoreKind, TOPIC_ID, SUBSCRIPTION_ID); | ||
// Await job creation | ||
TimeUnit.SECONDS.sleep(3); | ||
|
||
String output = bout.toString(); | ||
assertThat(output, containsString("Info type: PHONE_NUMBER")); | ||
assertThat(output, containsString("Info type: EMAIL_ADDRESS")); | ||
assertThat(output, containsString("Job created: ")); | ||
|
||
// Cancelling the job early to conserve quota | ||
String jobId = output.split("Job created: ")[1].split("\n")[0]; | ||
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build(); | ||
try (DlpServiceClient client = DlpServiceClient.create()) { | ||
client.cancelDlpJob(request); | ||
} | ||
Comment on lines
+136
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine if it works, but I'd bet these things can't happen right after the other. (some hysteresis). |
||
} | ||
|
||
@Test | ||
public void testInspectBigQueryTable() | ||
throws InterruptedException, ExecutionException, IOException { | ||
|
||
InspectBigQueryTable.inspectBigQueryTable( | ||
PROJECT_ID, DATASET_ID, TABLE_ID, TOPIC_ID, SUBSCRIPTION_ID); | ||
// Await job creation | ||
TimeUnit.SECONDS.sleep(3); | ||
|
||
String output = bout.toString(); | ||
assertThat(output, containsString("Info type: PHONE_NUMBER")); | ||
assertThat(output, containsString("Job created: ")); | ||
|
||
// Cancelling the job early to conserve quota | ||
String jobId = output.split("Job created: ")[1].split("\n")[0]; | ||
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build(); | ||
try (DlpServiceClient client = DlpServiceClient.create()) { | ||
client.cancelDlpJob(request); | ||
} | ||
Comment on lines
+155
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine if it works, but I'd bet these things can't happen right after the other. (some hysteresis). |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine if it works, but I'd bet these things can't happen right after the other. (some hysteresis).
(and it would be a flaky test again)