java system_error ai_generated true

java.lang.InterruptedException: sleep interrupted

ID: java/mockito-verify-timeout-interrupted

Also available as: JSON · Markdown · 中文
80%Fix Rate
81%Confidence
0Evidence
2024-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
8+ active

Root Cause

verify with timeout uses a background thread that gets interrupted, often due to test timeout or thread issues.

generic

中文

带有超时的 verify 使用后台线程,该线程被中断,通常由于测试超时或线程问题。

Workarounds

  1. 85% success Increase test timeout to accommodate verify timeout
    @Timeout(10)
    @Test
    void asyncTest() {
        verify(mock, timeout(5000)).method();
    }
  2. 90% success Use awaitility library for async tests
    await().atMost(5, SECONDS).untilAsserted(() -> {
        verify(mock).method();
    });

Dead Ends

Common approaches that don't work:

  1. Removing timeout from verify 60% fail

    May cause test to hang indefinitely.

  2. Catching InterruptedException and ignoring 50% fail

    Hides real threading issues; test may pass incorrectly.