codeandtheory / ynetwork-ios

A networking layer for iOS and tvOS.
Apache License 2.0
3 stars 3 forks source link

Fix flaky unit test #9

Closed mpospese closed 1 year ago

mpospese commented 1 year ago

NetworkManagerUploadTests.test_submitCancel_deliversError is flaky and intermittently failing.

This was never a problem previously, but has arisen when making the PR to adjust the SwiftLint rules. An attempt was made to fix it (which seemed to work), but then when merging that PR the test failed again.

When run locally the test always passes. From the Actions report I can see that the test is not timing out when executed on a GH runner as part of the action. I believe the problem is that the network call can complete as successful before it is canceled, which causes the test to fail (it expects that calling cancel will trigger an error).

Perhaps in the URLProtocolStubNetworkEngine we should add a property that controls whether tasks are automatically resumed when they are created. This would give the test a chance to cancel the task before it completes.

var autoresumes: Bool = true`

Maybe this should actually be a configuration property (NetworkManagerConfiguration or NetworkEngineConfiguration) to be used by all engine implementations and not just the URLProtocolStubNetworkEngine.