Skip to content
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

Tests: replace sleep with Thread.sleep(forTimeInterval:) #616

Merged
merged 1 commit into from
Jun 12, 2023

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Jun 7, 2023

sleep is not portable as it is not a standard C function. Use the Foundation function to provide a single codepath across all the targets.

Copy link
Contributor

@Kyle-Ye Kyle-Ye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Windows part this is totally fine.

But for macOS or Linux side, the implementation will change from Darwin.sleep to a Thread.sleep implementation on Foundation.

I am not familiar with the implementation of both and does not know whether it will give us different behavior.

Source: https://github.com/apple/swift-corelibs-foundation/blob/bd2e810a3ff5adf12410666cee74725d94f2dd25/Sources/Foundation/Thread.swift#L121-L156

Should we use a if directive to make sure other platform's behavior is not effected or just use Thread.sleep for all platforms? cc @franklinsch

#if os(Windows)
Thread.sleep(xx)
#else
_ = sleep(xx)
#endif

@compnerd
Copy link
Member Author

compnerd commented Jun 8, 2023

Thread.sleep(forTimeInterval:) gives a uniform way to handle sleeping. This is used pretty extensively in the Swift project. There is a Sleep function on Windows that does sleep for the number of seconds.

`sleep` is not portable as it is not a standard C function.  Use the
Foundation function to provide a single codepath across all the targets.
Copy link
Contributor

@daniel-grumberg daniel-grumberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me since this is just in testing code.

@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd compnerd merged commit 55f84fa into swiftlang:main Jun 12, 2023
@compnerd compnerd deleted the now-i-sleep branch June 12, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants