Skip to content

Commit 748a9e4

Browse files
authored
Merge pull request #379 from lensesio-dev/fix/cleanup-obsolete-locks-flaky-test
test(cloud-sink): fix interrupt-flag leak flaking IndexManagerV2Test
2 parents 601700b + 84b0f99 commit 748a9e4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • kafka-connect-cloud-common/src/test/scala/io/lenses/streamreactor/connect/cloud/common/sink/seek

kafka-connect-cloud-common/src/test/scala/io/lenses/streamreactor/connect/cloud/common/sink/seek/IndexManagerV2Test.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class IndexManagerV2Test
7575
private var indexManagerV2: IndexManagerV2 = _
7676

7777
before {
78+
// Defensive: a prior test (e.g. "drainGcQueue catches InterruptedException ...") can leave
79+
// the current thread's interrupt flag set — close()'s final drainGcQueue / awaitTermination
80+
// re-raises it after the test's own clear. cats-effect's unsafeRunSync() in open() returns
81+
// None on an interrupted thread, which surfaces as NoSuchElementException: None.get. Clear any
82+
// leaked interrupt state before each test so the flake cannot propagate between tests.
83+
val _ = Thread.interrupted()
7884
reset(storageInterface, connectorTaskId, bucketAndPrefixFn, pendingOperationsProcessors)
7985

8086
indexManagerV2 = new IndexManagerV2(
@@ -4417,8 +4423,12 @@ class IndexManagerV2Test
44174423
// Polled item was re-enqueued, not silently dropped.
44184424
im.gcQueueSize shouldBe 1
44194425
} finally {
4420-
Thread.interrupted() // clean up interrupt flag for subsequent tests
4426+
// Order matters: close() runs a final drainGcQueue() (with deleteFiles still stubbed to
4427+
// throw InterruptedException) and awaitTermination(), both of which RESTORE the interrupt
4428+
// flag. Clearing it must therefore happen AFTER close(), or the flag leaks into the next
4429+
// test and breaks its unsafeRunSync(). The defensive clear in `before` is the backstop.
44214430
im.close()
4431+
val _ = Thread.interrupted() // clean up interrupt flag for subsequent tests
44224432
}
44234433
}
44244434

0 commit comments

Comments
 (0)