-
Notifications
You must be signed in to change notification settings - Fork 2
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
…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.
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.
@@ -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.
} | ||
|
||
/** | ||
* 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.
} | ||
} | ||
|
||
/** | ||
* 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.
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.
|| 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.
|| 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.
📜 Description
Changes proposed in this pull request:
✅ Checklist: