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

SR-1872 Using RunLoopSource in XCTestCase.waitForExpectations #304

Conversation

pranavshenoy
Copy link

SR-1872 Replacing polling expectations to check whether an expectation is fulfilled with RunloopSource

@stmontgomery stmontgomery self-requested a review May 26, 2020 12:45
@lxbndr
Copy link
Contributor

lxbndr commented May 26, 2020

Could not compile on Windows :( I guess it is because CF is private to Foundation on Win platform.

@pranavshenoy
Copy link
Author

@lxbndr Thanks for pointing the issue.

Could you please direct me in which way I should Proceed

  1. Write CF wrappers like the one for public func _stop() . In this case, should I first raise a pull request for Foundation framework and once it gets merged, continue with the changes in XCTests or is there any other process to be followed that i am unaware of.

  2. Make these changes specific to non-Windows platform using #if os(Windows).

@lxbndr
Copy link
Contributor

lxbndr commented May 26, 2020

@pranavshenoy I'd choose p.2, as it looks problematic to write decent wrappers. AFAIK CFRunLoopSource doesn't have any Foundation counterparts.

Maybe we should implement p.2 as part of this PR, and then address Windows specifics as separate patch.

@compnerd would you like to recommend something here?

@compnerd
Copy link
Member

CC @millenomi
The CoreFoundation APIs are not meant to be used outside of Foundation is my understanding. I think that we need to modify Foundation first to expose the desired interface and use that.

@pranavshenoy
Copy link
Author

@compnerd @lxbndr Thanks for the response.
Shall I go ahead and raise a seperate pull request for adding CFRunloopSource wrappers in Foundation or is there any other procedure to be followed before making the changes. Please let me know.

@millenomi
Copy link

millenomi commented May 27, 2020

That PR is now out: swiftlang/swift-corelibs-foundation#2807

XCTest is cleared to use these wrappers, and as a change of policy _stop() is also now a cross-platform SPI rather than just Windows-only, so I suggest removing that #if os(Windows).

You want something like:

let source = RunLoop._Source()
runLoop._add(source, in: .default)



source.signal()



source.invalidate()

@millenomi
Copy link

millenomi commented May 27, 2020

To be clear, no one else is cleared to use them unless they talk to me first, so I can track changes if we need to change it.

Edit: meaning: no other project than XCTest.

@millenomi
Copy link

The SPI has been merged. Go ahead.

@pranavshenoy
Copy link
Author

pranavshenoy commented May 30, 2020

@millenomi I used wrapper but when I ran the tests, it was crashing..

Tried debugging it. The crash was occuring during _add() method.. On further analysis, got to know that crash is due to the hash closure in context definition

{ (info) -> CFHashCode in let me = Unmanaged<_Source>.fromOpaque(info!).takeUnretainedValue() return CFHashCode(me.hashValue) }
I tired printing the value, it indeed has some value. I am not sure why its happening..

I passed nil for "hash:" argument and the tests succeeded..

@millenomi
Copy link

I’ll take that patch. I’m sure it’s a memory management timing issue.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

I'll try to run the tests on Windows. Now that a few other things have been cleaned up, I think that I will try to actually get the XCTest test suite enabled on Windows for regular testing. It previously was passing but was not part of the nightly runs.

Sources/XCTest/Public/Asynchronous/XCTWaiter.swift Outdated Show resolved Hide resolved
Sources/XCTest/Public/Asynchronous/XCTWaiter.swift Outdated Show resolved Hide resolved
@pranavshenoy
Copy link
Author

I'll try to run the tests on Windows. Now that a few other things have been cleaned up, I think that I will try to actually get the XCTest test suite enabled on Windows for regular testing. It previously was passing but was not part of the nightly runs.

@compnerd shouldn't the issue (unable to add source using _add() ) be fixed before testing on Windows? Or is the patch already merged?

cc: @millenomi

@compnerd
Copy link
Member

compnerd commented Jun 4, 2020

Ah, okay, Ill hold off until you give me the green light :)

@pranavshenoy
Copy link
Author

pranavshenoy commented Jun 4, 2020

Ah, okay, Ill hold off until you give me the green light :)

Thanks @compnerd . I will locally run the Functional tests once @millenomi 's patch is merged to Foundation.

@pranavshenoy
Copy link
Author

I’ll take that patch. I’m sure it’s a memory management timing issue.

@millenomi Is there anything that I can do in this patch fix? please let me know.
Thanks

@pranavshenoy
Copy link
Author

I’ll take that patch. I’m sure it’s a memory management timing issue.

@millenomi Is there anything that I can do in this patch fix? please let me know.

@pranavshenoy
Copy link
Author

pranavshenoy commented Aug 5, 2020

@compnerd I have been trying to figure out if I could fix the issue with changes in Foundation framework done for this PR. (Adding CFRunloop api wrapper in Runloop.swift )..

To give a recap, the issue

@millenomi I used wrapper but when I ran the tests, it was crashing..

Tried debugging it. The crash was occuring during _add() method.. On further analysis, got to know that crash is due to the hash closure in context definition

{ (info) -> CFHashCode in let me = Unmanaged<_Source>.fromOpaque(info!).takeUnretainedValue() return CFHashCode(me.hashValue) }
I tired printing the value, it indeed has some value. I am not sure why its happening..

I passed nil for "hash:" argument and the tests succeeded..

I couldn't get any documentation regarding what the hash closure is expecting. Most examples I went through were having nil as the value.. can you tell me if I can pass nil to the hash argument and raise the PR to foundation framework? Or is there any way that we could fix that issue?

cc: @stmontgomery @millenomi

@pranavshenoy
Copy link
Author

@millenomi @compnerd I guess i got why its crashing..

hash: { (info) -> CFHashCode in let me = Unmanaged<_Source>.fromOpaque(info!).takeUnretainedValue() return CFHashCode(me.hashValue) },

In some cases, me.hashValue is negative value where the argument for CFHashCode is supposed to be unsigned integer.. I tried passing some positive number and it worked...

@pranavshenoy pranavshenoy changed the title Using RunLoopSource in XCTestCase.waitForExpectations SR-1872 Using RunLoopSource in XCTestCase.waitForExpectations Aug 9, 2020
@pranavshenoy pranavshenoy requested a review from compnerd August 9, 2020 11:23
@compnerd
Copy link
Member

compnerd commented Aug 9, 2020

@swift-ci please test

@millenomi
Copy link

If I can, I'm going to have a patch today for the crasher.

@pranavshenoy
Copy link
Author

pranavshenoy commented Aug 23, 2020 via email

@millenomi
Copy link

millenomi commented Aug 24, 2020

This should fix your _Source issues: swiftlang/swift-corelibs-foundation#2857

@millenomi
Copy link

@swift-ci please test

@pranavshenoy pranavshenoy requested a review from compnerd October 2, 2020 17:21
@shahmishal shahmishal closed this Oct 6, 2020
@shahmishal
Copy link
Member

shahmishal commented Oct 6, 2020

The Swift project moved the default branch to main and deleted master branch, so GitHub automatically closed the PR. Please rebase on top of the main and we can reopen.

More detail about the branch update - https://forums.swift.org/t/updating-branch-names/40412

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.

5 participants