forked from swiftwasm/JavaScriptKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebWorkerDedicatedExecutorTests.swift
More file actions
35 lines (31 loc) · 1.13 KB
/
WebWorkerDedicatedExecutorTests.swift
File metadata and controls
35 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#if compiler(>=6.1) && _runtime(_multithreaded)
import XCTest
@testable import JavaScriptEventLoop
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
final class WebWorkerDedicatedExecutorTests: XCTestCase {
actor MyActor {
let executor: WebWorkerDedicatedExecutor
nonisolated var unownedExecutor: UnownedSerialExecutor {
self.executor.asUnownedSerialExecutor()
}
init(executor: WebWorkerDedicatedExecutor) {
self.executor = executor
XCTAssertTrue(isMainThread())
}
func onWorkerThread() async {
XCTAssertFalse(isMainThread())
await Task.detached {}.value
// Should keep on the thread after back from the other isolation domain
XCTAssertFalse(isMainThread())
}
}
func testEnqueue() async throws {
let executor = try await WebWorkerDedicatedExecutor()
defer { executor.terminate() }
let actor = MyActor(executor: executor)
XCTAssertTrue(isMainThread())
await actor.onWorkerThread()
XCTAssertTrue(isMainThread())
}
}
#endif