fix SAL non-determinism (#1562)

Motivation:

The SAL tests suffered from a rare non-determinism: When we go onto the
EventLoop to get a value and then leave it, we previously just assumed
that the EventLoop would park itself before we did any futher operations
on it.

That was mostly true because the tests are doing one thing after the
other. There was however a narrow race: If the tests enqueued new work
onto the EventLoop before the EventLoop parked itself, then the new work
would be run _before_ the EL parks itself.

That would make the _next_ operation fail because the operations usually
start by checking that we're parked because that's a synchronisation
point between tests and EL.

Modifications:

Actually wait until the EL's parked. That proves we found our
synchronisation point.

Result:

- fixes #1514
- fixes #1545
- fixes #1548
- fixes #1550
This commit is contained in:
Johannes Weiss authored and GitHub committed 2020-06-18 18:01:30 +01:00
1 parent 6046aaa629
commit d371bb5a10
1 file changed
+18 -7
+18 -7
View File
@@ -114,6 +114,18 @@ final class LockedBox<T> {
}
}
extension LockedBox where T == UserToKernel {
func assertParkedRightNow(file: StaticString = #file, line: UInt = #line) throws {
SAL.printIfDebug("\(#function)")
let syscall = try self.waitForValue()
if case .whenReady = syscall {
return
} else {
XCTFail("unexpected syscall \(syscall)", file: (file), line: line)
}
}
}
enum UserToKernel {
case localAddress
case remoteAddress
@@ -392,6 +404,9 @@ extension HookedSelector {
try self.wakeups.takeValue()
}
func assertParkedRightNow(file: StaticString = #file, line: UInt = #line) throws {
try self.userToKernel.assertParkedRightNow(file: file, line: line)
}
}
extension EventLoop {
@@ -410,6 +425,7 @@ extension EventLoop {
}
try hookedSelector.assertWakeup(file: (file), line: line)
try syscallAssertions()
try hookedSelector.userToKernel.assertParkedRightNow() // We need the EventLoop to finish running its tick.
return try box.takeValue().get()
}
}
@@ -434,6 +450,7 @@ extension EventLoopFuture {
}
}
try hookedSelector.assertWakeup()
try hookedSelector.userToKernel.assertParkedRightNow() // We need the EventLoop to finish running its tick.
return try box.takeValue().get()
}
}
@@ -585,13 +602,7 @@ extension SALTest {
}
func assertParkedRightNow(file: StaticString = #file, line: UInt = #line) throws {
SAL.printIfDebug("\(#function)")
let syscall = try self.userToKernelBox.waitForValue()
if case .whenReady = syscall {
return
} else {
XCTFail("unexpected syscall \(syscall)", file: (file), line: line)
}
try self.userToKernelBox.assertParkedRightNow(file: file, line: line)
}
func assertWaitingForNotification(result: SelectorEvent<NIORegistration>?,