Skip to content

Fix flaky unit test #9

@mpospese

Description

@mpospese

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions