-
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
Increase Logging Testing stability #903
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 |
---|---|---|
|
@@ -39,6 +39,9 @@ | |
@SuppressWarnings("checkstyle:abbreviationaswordinname") | ||
public class LoggingIT { | ||
|
||
private final String QUICKSTART_LOG = "my-log"; | ||
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. Should these go to $TEMP? 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. This is the name of the log in StackDriver that it can later be referred by, not the location it's logging too. 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. SGTM |
||
private final String TEST_WRITE_LOG = "test-log"; | ||
|
||
private ByteArrayOutputStream bout; | ||
private PrintStream out; | ||
private Logging logging = LoggingOptions.getDefaultInstance().getService(); | ||
|
@@ -56,37 +59,36 @@ public void setUp() { | |
|
||
@After | ||
public void tearDown() { | ||
// Clean up created logs | ||
deleteLog(QUICKSTART_LOG); | ||
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. do you want to do this 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. I'm concerned that part of the reasons the tests are failing periodically is that the deletes are actually being registered after the test line is logged. By moving the cleanup to the tearDown, it should always clean up unless the build is somehow forced to stop between the file log and that this exact moment. 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. I'm just concerned that some crash happens and it doesn't execute - so I ask Q's. If you are happy, I'm happy. (ie you don't think that will happen) 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. sgtm |
||
deleteLog(TEST_WRITE_LOG); | ||
|
||
System.setOut(null); | ||
} | ||
|
||
@Test | ||
public void testQuickstart() throws Exception { | ||
String logName = "my-log"; | ||
deleteLog(logName); | ||
QuickstartSample.main(logName); | ||
QuickstartSample.main(QUICKSTART_LOG); | ||
String got = bout.toString(); | ||
assertThat(got).contains("Logged: Hello, world!"); | ||
deleteLog(logName); | ||
} | ||
|
||
@Test(timeout = 10000) | ||
@Test(timeout = 20000) | ||
public void testWriteAndListLogs() throws Exception { | ||
String logName = "test-log"; | ||
deleteLog(logName); | ||
// write a log entry | ||
LogEntry entry = LogEntry.newBuilder(StringPayload.of("Hello world again")) | ||
.setLogName(logName) | ||
.setLogName(TEST_WRITE_LOG) | ||
.setResource(MonitoredResource.newBuilder("global").build()) | ||
.build(); | ||
logging.write(Collections.singleton(entry)); | ||
// flush out log immediately | ||
logging.flush(); | ||
bout.reset(); | ||
// Check if the log is listed yet | ||
while (bout.toString().isEmpty()) { | ||
ListLogs.main(logName); | ||
ListLogs.main(TEST_WRITE_LOG); | ||
Thread.sleep(1000); | ||
} | ||
assertThat(bout.toString().contains("Hello world again")).isTrue(); | ||
deleteLog(logName); | ||
} | ||
} |
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.
There are forms of getting entries that aren't fully paged, but are infinite. I'm presuming you've verified that this is actually paged?