-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NIOAsyncWriterSinkDelegate._didSuspend hook for testing #2597
Add NIOAsyncWriterSinkDelegate._didSuspend hook for testing #2597
Conversation
0208d98
to
cc38e09
Compare
cc38e09
to
31468a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate it but it solves the flakiness, so let's do it! We should probably do the same for the NIO[Throwing]AsyncSequenceProducer
tests. Do you mind doing the same there? Can even put it into this PR if you want!
@@ -13,7 +13,7 @@ | |||
//===----------------------------------------------------------------------===// | |||
|
|||
import DequeModule | |||
import NIOCore | |||
@testable import NIOCore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer if we don't use @testable
. It is a horrible compiler hack and I would love to slowly get away from it by either using SPI
or the new package
modifier. For now let's use @_spi(Testing)
and we can migrate that in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, discussed this offline.
I think we agreed that what we really want here is package
, but we cannot use that today. Making it SPI might have a performance impact when compiled without -enable-testability
because we'd have to make some things public
(SPI) that were internal
, which could impact the optimisations possible.
I'm pretty flexible at this point. I have a lean toward @testable import
because it leaves the release build unaffected, but if you'd like I can do the SPI dance before we merge.
Added commit to give the |
de8d0d5
to
303eb78
Compare
Motivation:
The tests for the
NIOAsyncWriter
currently rely on a number ofTask.sleep
calls to wait for tasks to be suspended or cancelled before performing some other operation. These have been shown to be flakey in CI. We could just increase all the sleeps, but instead we can make use ofXCTestExpectation
to wait for things to happen. The events that we are waiting on are these:This didn't require any additional changes to the writer for (1) and can just wait for an expectation inside the task that we fulfil after the cancelling the task from outside.
For (2) we need to have a hook that we can use when the task has performed the state transition and is parked that we can use to fulfil the expectation.
Modifications:
_didSuspend
optional closure toNIOAsyncWriterSinkDelegate
.Task.sleep(nanoseconds:)
in tests withawait fulfillment(of:[timeout:])
.Result:
Tests should be more deterministic.