Skip to content

Commit 6c8328f

Browse files
committed
Check logs for errors at smoke tests cleanup
1 parent a19f73a commit 6c8328f

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

dd-smoke-tests/armeria-grpc/src/test/groovy/datadog/smoketest/ArmeriaSmokeTest.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class ArmeriaSmokeTest extends AbstractServerSmokeTest {
5757
})
5858
waitForTraceCount(totalInvocations) >= totalInvocations
5959
validateLogInjection() == totalInvocations
60-
checkLogPostExit()
61-
!logHasErrors
60+
assertNoErrorLogs()
6261
}
6362

6463
void doAndValidateRequest(int id) {

dd-smoke-tests/custom-systemloader/src/test/groovy/datadog/smoketest/CustomSystemLoaderSmokeTest.groovy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ class CustomSystemLoaderSmokeTest extends AbstractSmokeTest {
3030
def "resource types loaded by custom system class-loader are transformed"() {
3131
when:
3232
testedProcess.waitFor(TIMEOUT_SECS, SECONDS)
33+
34+
then:
35+
testedProcess.exitValue() == 0
3336
int loadedResources = 0
3437
int transformedResources = 0
35-
checkLogPostExit {
38+
assertNoErrorLogs { String it ->
3639
if (it =~ /Loading sample.app.Resource[$]Test[1-3] from TestLoader/) {
3740
loadedResources++
3841
}
3942
if (it =~ /Transformed.*class=sample.app.Resource[$]Test[1-3].*classloader=datadog.smoketest.systemloader.TestLoader/) {
4043
transformedResources++
4144
}
45+
false
4246
}
43-
then:
44-
testedProcess.exitValue() == 0
4547
loadedResources == 3
4648
transformedResources == 3
47-
!logHasErrors
4849
}
4950
}

dd-smoke-tests/src/main/groovy/datadog/smoketest/AbstractSmokeTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ abstract class AbstractSmokeTest extends ProcessManager {
243243

244244
def cleanupSpec() {
245245
stopServer()
246+
assertNoErrorLogs()
246247
}
247248

248249
def startServer() {

dd-smoke-tests/src/main/groovy/datadog/smoketest/ProcessManager.groovy

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,49 @@ abstract class ProcessManager extends Specification {
252252
return "http://localhost:${profilingPort}/"
253253
}
254254

255+
/**
256+
* Asserts that there are no errors printed by the application to the log.
257+
*/
258+
void assertNoErrorLogs() {
259+
assertNoErrorLogs({ false })
260+
}
261+
262+
/**
263+
* Checks if a log line is an error. This method may be overridden by test suites to consider additional messages.
264+
* These will be checked on suite shutdown, or explicitly by calling {@link #assertNoErrorLogs()}.
265+
*/
266+
boolean isErrorLog(String line) {
267+
return line.contains("ERROR") || line.contains("ASSERTION FAILED")
268+
|| line.contains("Failed to handle exception in instrumentation")
269+
}
270+
271+
/**
272+
* Asserts that there are no errors printed by the application to the log.
273+
* This should only be called after the process exits, otherwise it's not guaranteed that reading the log file will
274+
* yield its final contents. Most tests should not need this, since it will be called at the end of every smoke test
275+
* suite.
276+
*
277+
* @param isErrorLog Returns true if certain log line must be considered an error (in addition to defaults).
278+
*/
279+
void assertNoErrorLogs(final Closure<Boolean> extraIsErrorLog) {
280+
final Closure<Boolean> effectiveIsErrorLog = { String it -> isErrorLog(it) || extraIsErrorLog(it) }
281+
final List<String> errorLogs = new ArrayList<>()
282+
for (String lfp : logFilePaths) {
283+
ProcessManager.eachLine(new File(lfp)) {
284+
if (effectiveIsErrorLog(it)) {
285+
errorLogs << it
286+
}
287+
}
288+
}
289+
if (!errorLogs.isEmpty()) {
290+
final StringBuilder sb = new StringBuilder("Test application log contains ${errorLogs.size()} errors:\n")
291+
errorLogs.eachWithIndex { String entry, int i ->
292+
sb.append("${i + 1}: ${entry}\n")
293+
}
294+
assert errorLogs.isEmpty(), sb.toString()
295+
}
296+
}
297+
255298
/**
256299
* Check the test application log and set {@linkplain AbstractSmokeTest#logHasErrors} variable
257300
*

0 commit comments

Comments
 (0)