Skip to content

[monotouch-test] Add timeouts to all Thread.Join calls#25644

Merged
rolfbjarne merged 3 commits into
mainfrom
dev/rolf/tests-thread-timed-join
Jun 5, 2026
Merged

[monotouch-test] Add timeouts to all Thread.Join calls#25644
rolfbjarne merged 3 commits into
mainfrom
dev/rolf/tests-thread-timed-join

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Jun 4, 2026

Copy link
Copy Markdown
Member

Replace all Thread.Join() calls (no timeout) in monotouch-test with Thread.Join(TimeSpan) + Assert.That to fail the test if the thread does not complete within a reasonable time, instead of hanging indefinitely.

Additionally, all affected threads are marked as background threads (IsBackground = true) so that if a Join times out, the orphaned thread does not keep the test process alive.

Timeouts are chosen based on the work each thread does:

  • 5s for simple/fast operations (object creation, property checks)
  • 10s for I/O or RunLoop-based threads (timers, network listeners, sublayer creation)
  • 30s for heavy workloads (10k iterations, GPU image processing)

🤖 Pull request created by Copilot

Replace all Thread.Join() calls (no timeout) with
Thread.Join(TimeSpan) + Assert.That to fail the test if the
thread doesn't complete within a reasonable time. Timeouts
are chosen based on the work each thread does:

- 5s for simple/fast operations (object creation, property checks)
- 10s for I/O or RunLoop-based threads (timers, network listeners)
- 30s for heavy workloads (10k iterations, GPU image processing)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 4, 2026 07:29
@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the tests/monotouch-test suite to avoid indefinite hangs by replacing Thread.Join() (no timeout) with Thread.Join(TimeSpan) and an Assert.That to fail tests when worker threads don’t complete within a bounded time.

Changes:

  • Replaced unbounded Thread.Join() calls with bounded Join(TimeSpan) + Assert.That across multiple tests.
  • Selected per-test timeouts (5s/10s/30s) based on expected workload characteristics.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs Adds 5s Join timeouts for background-thread reachability GC/notification tests.
tests/monotouch-test/ObjCRuntime/RuntimeTest.cs Adds 5s Join timeouts for runtime/GC/thread interaction tests.
tests/monotouch-test/ObjCRuntime/RegistrarTest.cs Adds a 30s Join timeout for a heavy block-collection workload.
tests/monotouch-test/Foundation/TimerTest.cs Adds 10s Join timeouts for runloop/timer worker threads.
tests/monotouch-test/Foundation/ThreadTest.cs Adds a 5s Join timeout for a simple thread completion check.
tests/monotouch-test/Foundation/NSStreamTest.cs Adds a 10s Join timeout to the listener thread used for stream socket tests.
tests/monotouch-test/Foundation/NotificationCenter.cs Adds per-thread Join timeouts to the multithreaded add/remove observer stress test.
tests/monotouch-test/CoreImage/CIKernelTests.cs Adds a 30s Join timeout for CoreImage processing on a separate thread.
tests/monotouch-test/CoreAnimation/LayerTest.cs Adds 5s/10s Join timeouts for CALayer-related thread scenarios.

Comment on lines 76 to 80
Assert.That (result [i], Is.EqualTo (send [i] * 10));
listenThread.Join ();
Assert.That (listenThread.Join (TimeSpan.FromSeconds (10)), Is.True, "listenThread.Join timed out");
listener.Stop ();
read.Close ();
write.Close ();
Comment on lines 225 to +226
thread.Start ();
thread.Join ();
Assert.That (thread.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out");
Comment on lines 268 to +269
thread.Start ();
thread.Join ();
Assert.That (thread.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out");
Comment on lines 559 to +560
t1.Start ();
t1.Join ();
Assert.That (t1.Join (TimeSpan.FromSeconds (5)), Is.True, "Thread.Join timed out");
Comment on lines 2126 to +2127
thread.Start ();
thread.Join ();
Assert.That (thread.Join (TimeSpan.FromSeconds (30)), Is.True, "Thread.Join timed out");
Comment on lines 157 to +158
t.Start ();
t.Join ();
Assert.That (t.Join (TimeSpan.FromSeconds (30)), Is.True, "Thread.Join timed out");
Comment on lines 135 to +136
thread.Start ();
thread.Join ();
Assert.That (thread.Join (TimeSpan.FromSeconds (10)), Is.True, "Thread.Join timed out");
@vs-mobiletools-engineering-service2

This comment has been minimized.

If a Join times out and the thread is a foreground thread, it can
keep the test process alive. Mark all affected threads as background
so they don't block process exit on timeout.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne enabled auto-merge (squash) June 4, 2026 08:52
@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #9fd53a3] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 9fd53a3628dd267753ba83384dc25f986ea6d957 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #9fd53a3] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 9fd53a3628dd267753ba83384dc25f986ea6d957 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 9fd53a3628dd267753ba83384dc25f986ea6d957 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #9fd53a3] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 9fd53a3628dd267753ba83384dc25f986ea6d957 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #9fd53a3] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 193 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 11 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 23 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 23 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 tests passed. [attempt 3] Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 9fd53a3628dd267753ba83384dc25f986ea6d957 [PR build]

@rolfbjarne rolfbjarne merged commit cb474e4 into main Jun 5, 2026
55 checks passed
@rolfbjarne rolfbjarne deleted the dev/rolf/tests-thread-timed-join branch June 5, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants