Skip to content

Commit

Permalink
Merge branch 'main' into cb-strict-concurrency-embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasa authored Dec 16, 2024
2 parents 4019a8f + 1a3229b commit 0291379
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Tests/NIOPosixTests/NIOScheduledCallbackTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ protocol ScheduledCallbackTestRequirements {

// ELG-backed ELs need to be shutdown via the ELG.
func shutdownEventLoop() async throws

func waitForLoopTick() async throws
}

final class MTELGScheduledCallbackTests: _BaseScheduledCallbackTests {
Expand All @@ -41,6 +43,10 @@ final class MTELGScheduledCallbackTests: _BaseScheduledCallbackTests {
func shutdownEventLoop() async throws {
try await self.group.shutdownGracefully()
}

func waitForLoopTick() async throws {
try await self.loop.submit {}.get()
}
}

override func setUp() async throws {
Expand All @@ -60,6 +66,10 @@ final class NIOAsyncTestingEventLoopScheduledCallbackTests: _BaseScheduledCallba
func shutdownEventLoop() async throws {
await self._loop.shutdownGracefully()
}

func waitForLoopTick() async throws {
try await self._loop.executeInContext {}
}
}

override func setUp() async throws {
Expand All @@ -83,6 +93,7 @@ extension _BaseScheduledCallbackTests {

func advanceTime(by amount: TimeAmount) async throws {
try await self.requirements.advanceTime(by: amount)
try await self.requirements.waitForLoopTick()
}

func shutdownEventLoop() async throws {
Expand Down Expand Up @@ -151,6 +162,7 @@ extension _BaseScheduledCallbackTests {

let scheduledCallback = try self.loop.scheduleCallback(in: .milliseconds(1), handler: handler)
scheduledCallback.cancel()
try await self.requirements.waitForLoopTick()
handler.assert(callbackCount: 0, cancelCount: 1)
}

Expand All @@ -161,6 +173,7 @@ extension _BaseScheduledCallbackTests {
try await self.advanceTime(by: .milliseconds(1))
try await handler.waitForCallback(timeout: .seconds(1))
scheduledCallback.cancel()
try await self.requirements.waitForLoopTick()
handler.assert(callbackCount: 1, cancelCount: 0)
}

Expand All @@ -169,7 +182,9 @@ extension _BaseScheduledCallbackTests {

let scheduledCallback = try self.loop.scheduleCallback(in: .milliseconds(1), handler: handler)
scheduledCallback.cancel()
try await self.requirements.waitForLoopTick()
scheduledCallback.cancel()
try await self.requirements.waitForLoopTick()
handler.assert(callbackCount: 0, cancelCount: 1)
}

Expand Down Expand Up @@ -197,6 +212,7 @@ extension _BaseScheduledCallbackTests {

let handle = try self.loop.scheduleCallback(in: .milliseconds(1), handler: handler)
handle.cancel()
try await self.requirements.waitForLoopTick()
handler.assert(callbackCount: 0, cancelCount: 1)

try await self.shutdownEventLoop()
Expand Down

0 comments on commit 0291379

Please sign in to comment.