Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded unit test for reentrancy. #95
Conversation
|
cc @pcwalton |
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| struct HasWeirdSerializer (Option<String>); | ||
|
|
||
| lazy_static! { static ref WEIRD_CHANNEL: (IpcSender<HasWeirdSerializer>, IpcReceiver<HasWeirdSerializer>) = ipc::channel().unwrap(); } |
This comment has been minimized.
This comment has been minimized.
antrik
Aug 9, 2016
•
Contributor
A non-reentrant testcase for reentrance? Now that's just lazy! ;-)
I guess it's not really a problem, unless the test harness ever grows an ability to run the same test multiple times in parallel, which seems rather hypothetical...
|
For what it's worth, this looks good to me. (I'm happy to see a testcase being added for obscure behaviour someone will be relying on -- a very good practice that probably should be employed more often :-) ) |
|
Travis is displeased:
|
|
Not sure why I'm not getting this error on my end... I'll put it in a rw mutex or some such and retry. |
|
@asajeffrey on what platform(s) have you tested this? The definition of |
|
The test isn't to see if it's thread-safe, it's to see if it's reentrant. Since IPC channels serialize to a fresh buffer each time, it should be reentrant. |
|
@asajeffrey well, that's not what the test is about -- but since |
|
Indeed, since it's a global it has to be sync. Rather ironically this is exactly the use case for reentrant locks, which is what got is here in the first place. Probably easiest just to make it thread-local. I'm not at my desk today, I'll do this tomorrow. |
|
I made Travis happy by making the global thread-local. |
| Ok(HasWeirdSerializer(try!(Deserialize::deserialize(deserializer)))) | ||
| } | ||
| } | ||
|
|
This comment has been minimized.
This comment has been minimized.
antrik
Aug 13, 2016
Contributor
Personally I think it would be more readable to put all this stuff right before the (only) test case using it...
This comment has been minimized.
This comment has been minimized.
| let hello = HasWeirdSerializer(Some(String::from("hello"))); | ||
| let (sender, receiver) = ipc::channel().unwrap(); | ||
| let sender1 = sender.clone(); | ||
| WEIRD_CHANNEL.with(|chan| { *chan.borrow_mut() = Some(sender1); }); |
This comment has been minimized.
This comment has been minimized.
antrik
Aug 13, 2016
Contributor
Nitpick: since this is not a move closure, it seem circuitous to do the clone() beforehand -- I think it would be cleaner simply to do Some(sender.clone()) within the closure...
This is mostly just a general hint though -- as we are talking about test code here, I wouldn't insist on fixing such a minor stylistic wrinkle :-)
This comment has been minimized.
This comment has been minimized.
|
@asajeffrey thanks :-) Please squash the commits -- and then we just need someone with official reviewer status to approve it... |
|
Squashed. |
|
Meh, there is an intermittent failure it seems? This definitely shouldn't be affected by these changes... |
|
Yes, that is odd... timeouts on unrelated tests? |
|
Just to be clear: I really don't think this test failure has anything to do with this PR. Either the test case in question has intermittent failures, or there was some one-time hiccup on Travis. @pcwalton r? |
|
|
|
Looks good once the conflicts are resolved. |
36af002
to
525f6d6
|
@bors-servo r=pcwalton |
|
|
Added unit test for reentrancy. IPC channels are reentrant, in that if we call `c.send(a)` and serializing `a` calls `c.send(b)`, then the channel contents are `b` then `a`. (This comes up in the case of logging over channels, since serialization may include logging.) This PR adds a unit test to make sure we don't break reentrancy. Discussion with @nox on IRC.
|
|
asajeffrey commentedAug 9, 2016
IPC channels are reentrant, in that if we call
c.send(a)and serializingacallsc.send(b), then the channel contents arebthena. (This comes up in the case of logging over channels, since serialization may include logging.)This PR adds a unit test to make sure we don't break reentrancy.
Discussion with @nox on IRC.