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

Implement Auto Deadlock detection on Test Timeout via JUnit5 Test Extension Annotation #97

Conversation

DivineThreepwood
Copy link
Member

@DivineThreepwood DivineThreepwood commented Jan 28, 2023

📜 Description

Changes proposed in this pull request:

  • Add timeouts to all test annotations.
  • Implement test plugin that prints stacktraces or detected deadlocks on test timeouts.
  • Introduce dedicated jul test module to bundle all further test classes.
  • Port Stacktrace printer from java to kotlin.
  • Cleanup generated headers of gradle build files.
  • Cleanup some code sections.
  • Cleanup empty tests.

✅ Checklist:

  • Created tests which fail without the change (if possible)

…s stacktraces or detected deadlocks on test timeouts. Introduce dedecated jul test module.
* In case one is detected the affected stack traces are printed including the lock access.
*
* @param logger the logger used for the report in case deadlocks are detected.
*
* @return true in case deadlocks are detected, otherwise false.
*/
public static boolean detectDeadLocksAndPrintStackTraces(final Logger logger) {
@JvmStatic
fun detectDeadLocksAndPrintStackTraces(logger: Logger): Boolean {

Check warning

Code scanning / detekt

Excessive nesting leads to hidden complexity. Prefer extracting code to make it easier to understand.

Function detectDeadLocksAndPrintStackTraces is nested too deeply.
public class StackTracePrinter {

private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
object StackTracePrinter {

Check warning

Code scanning / detekt

Too many functions inside a/an file/class/object/interface always indicate a violation of the single responsibility principle. Maybe the file/class/object/interface wants to manage too many things at once. Extract functionality which clearly belongs together.

Object 'StackTracePrinter' with '12' functions detected. Defined threshold inside objects is set to '11'
@@ -0,0 +1,4 @@
package org.openbase.jul.communication.mqtt.test

class OpenbaseDeadlockChecker: OnTimeoutDeadlockChecker("org.openbase") {

Check warning

Code scanning / detekt

Empty block of code detected. As they serve no purpose they should be removed.

The class or object OpenbaseDeadlockChecker is empty.
}

/**
* Method prints the stack traces of all running java threads via the given logger.
*
* @param threadFilter only threads where the name of the thread contains this given {@code threadFilter} key are printed. If the filter is null, no filtering will be performed.
* @param threadFilter only threads where the name of the thread contains this given `threadFilter` key are printed. If the filter is null, no filtering will be performed.

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style.

Line detected that is longer than the defined maximum line length in the code style.
}
}

/**
* Method prints the stack traces of all running java threads via the given logger.
*
* @param filter only thread where the name of the thread contains this given {@code filter} key are printed. If the filter is null, no filtering will be performed.
* @param filter only thread where the name of the thread contains this given `filter` key are printed. If the filter is null, no filtering will be performed.

Check warning

Code scanning / detekt

Line detected that is longer than the defined maximum line length in the code style.

Line detected that is longer than the defined maximum line length in the code style.
for (Map.Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) {
@JvmStatic
fun printAllStackTraces(threadFilter: String?, classFilter: Class<*>?, logger: Logger?, logLevel: LogLevel?) {
for ((key, value) in Thread.getAllStackTraces()) {

Check warning

Code scanning / detekt

The loop contains more than one break or continue statement. The code should be refactored to increase readability.

The loop contains more than one break or continue statement. The code should be refactored to increase readability.
|| stacktrace.any { it.className.contains("org.openbase") }
}
.filterNot { (_, stacktrace) ->
filterWaitingWorkerThreads && stacktrace.size > 4 && stacktrace[stacktrace.size - 4].toString()

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers.

This expression contains a magic number. Consider defining it to a well named constant.
|| stacktrace.any { it.className.contains("org.openbase") }
}
.filterNot { (_, stacktrace) ->
filterWaitingWorkerThreads && stacktrace.size > 4 && stacktrace[stacktrace.size - 4].toString()

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers.

This expression contains a magic number. Consider defining it to a well named constant.
@DivineThreepwood DivineThreepwood merged commit 2d6455e into dev Jan 31, 2023
@DivineThreepwood DivineThreepwood deleted the 96-implement-auto-deadlock-detection-on-test-timeout-via-junit5-test-extension-annotation branch January 31, 2023 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Auto Deadlock detection on Test Timeout via JUnit5 Test Extension Annotation
2 participants