-
Notifications
You must be signed in to change notification settings - Fork 274
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
fixed ipc leak #277
Merged
Merged
fixed ipc leak #277
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
adc2f69
fixed ipc connection leak, closes #275
debris a3e4401
fixed indentation
debris 2ccdeb6
fixed broken pipe issue in tests
debris feecb98
empirical tests fixes
debris dd70e1f
fix tests
debris e39aca6
fix tests
debris 93be6f1
fix tests
debris 5ce80c7
move ipc start_signal.send after the incoming.for_each
debris cf248b9
log ipc traces on travis
debris 98a7dc2
keep writer in memory as long as possible
debris 8151fd5
select_with_weak
debris 15e6c03
remove redundant thread::sleep
debris a7630db
test session end
debris bb76cf3
fixed race condition in test_session_end
debris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,9 +247,11 @@ mod tests { | |
extern crate tokio_uds; | ||
|
||
use std::thread; | ||
use std::time::Duration; | ||
use super::{ServerBuilder, Server}; | ||
use jsonrpc::{MetaIoHandler, Value}; | ||
use jsonrpc::futures::{Future, future, Stream, Sink}; | ||
use jsonrpc::futures::sync::{mpsc, oneshot}; | ||
use self::tokio_uds::UnixStream; | ||
use server_utils::tokio_core::reactor::Core; | ||
use server_utils::tokio_io::AsyncRead; | ||
|
@@ -270,8 +272,7 @@ mod tests { | |
} | ||
|
||
fn dummy_request_str(path: &str, data: &str) -> String { | ||
let mut core = Core::new().expect("Tokio Core should be created with no errors"); | ||
|
||
let core = Core::new().unwrap(); | ||
let stream = UnixStream::connect(path, &core.handle()).expect("Should have been connected to the server"); | ||
let (writer, reader) = stream.framed(codecs::StreamCodec::stream_incoming()).split(); | ||
let reply = writer | ||
|
@@ -284,7 +285,7 @@ mod tests { | |
future::ok(reply.expect("there should be one reply")) | ||
}); | ||
|
||
core.run(reply).unwrap() | ||
reply.wait().unwrap() | ||
} | ||
|
||
#[test] | ||
|
@@ -316,58 +317,63 @@ mod tests { | |
::logger::init_log(); | ||
let path = "/tmp/test-ipc-40000"; | ||
let server = run(path); | ||
thread::sleep(::std::time::Duration::from_millis(1000)); | ||
let (stop_signal, stop_receiver) = oneshot::channel(); | ||
|
||
let result = dummy_request_str( | ||
path, | ||
"{\"jsonrpc\": \"2.0\", \"method\": \"say_hello\", \"params\": [42, 23], \"id\": 1}", | ||
let _ = thread::spawn(move || { | ||
let result = dummy_request_str( | ||
path, | ||
"{\"jsonrpc\": \"2.0\", \"method\": \"say_hello\", \"params\": [42, 23], \"id\": 1}", | ||
); | ||
stop_signal.send(result).unwrap(); | ||
}).join().unwrap(); | ||
|
||
let _ = stop_receiver.map(move |result: String| { | ||
assert_eq!( | ||
result, | ||
"{\"jsonrpc\":\"2.0\",\"result\":\"hello\",\"id\":1}", | ||
"Response does not exactly match the expected response", | ||
); | ||
|
||
assert_eq!( | ||
result, | ||
"{\"jsonrpc\":\"2.0\",\"result\":\"hello\",\"id\":1}", | ||
"Response does not exactly match the expected response", | ||
); | ||
|
||
thread::sleep(::std::time::Duration::from_millis(1000)); | ||
server.close(); | ||
server.close(); | ||
}).wait(); | ||
} | ||
|
||
#[test] | ||
fn req_parallel() { | ||
use std::thread; | ||
|
||
::logger::init_log(); | ||
let path = "/tmp/test-ipc-45000"; | ||
let server = run(path); | ||
thread::sleep(::std::time::Duration::from_millis(1000)); | ||
thread::sleep(Duration::from_millis(100)); | ||
let (stop_signal, stop_receiver) = mpsc::channel(400); | ||
|
||
let mut handles = Vec::new(); | ||
for _ in 0..4 { | ||
let path = path.clone(); | ||
let mut stop_signal = stop_signal.clone(); | ||
handles.push( | ||
thread::spawn(move || { | ||
thread::sleep(::std::time::Duration::from_millis(100)); | ||
for _ in 0..100 { | ||
let result = dummy_request_str( | ||
&path, | ||
"{\"jsonrpc\": \"2.0\", \"method\": \"say_hello\", \"params\": [42, 23], \"id\": 1}", | ||
); | ||
|
||
assert_eq!( | ||
result, | ||
"{\"jsonrpc\":\"2.0\",\"result\":\"hello\",\"id\":1}", | ||
"Response does not exactly match the expected response", | ||
); | ||
stop_signal.try_send(result).unwrap(); | ||
} | ||
}) | ||
); | ||
} | ||
thread::sleep(Duration::from_millis(100)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious: why do we still need to nap? |
||
|
||
for handle in handles.drain(..) { | ||
handle.join().unwrap(); | ||
} | ||
thread::sleep(::std::time::Duration::from_millis(1000)); | ||
|
||
let _ = stop_receiver.map(|result| { | ||
assert_eq!( | ||
result, | ||
"{\"jsonrpc\":\"2.0\",\"result\":\"hello\",\"id\":1}", | ||
"Response does not exactly match the expected response", | ||
); | ||
}).take(400).collect().wait(); | ||
server.close(); | ||
} | ||
|
||
|
@@ -410,22 +416,24 @@ mod tests { | |
let builder = ServerBuilder::new(io); | ||
|
||
let server = builder.start(path).expect("Server must run with no issues"); | ||
thread::sleep(::std::time::Duration::from_millis(1000)); | ||
let (stop_signal, stop_receiver) = oneshot::channel(); | ||
|
||
let result = dummy_request_str(&path, | ||
"{\"jsonrpc\": \"2.0\", \"method\": \"say_huge_hello\", \"params\": [], \"id\": 1}", | ||
); | ||
let _ = thread::spawn(move || { | ||
let result = dummy_request_str( | ||
&path, | ||
"{\"jsonrpc\": \"2.0\", \"method\": \"say_huge_hello\", \"params\": [], \"id\": 1}", | ||
); | ||
|
||
assert_eq!( | ||
result, | ||
huge_response_test_json(), | ||
"Response does not exactly match the expected response", | ||
); | ||
stop_signal.send(result).unwrap(); | ||
}).join().unwrap(); | ||
|
||
thread::sleep(::std::time::Duration::from_millis(1000)); | ||
server.close(); | ||
let _ = stop_receiver.map(move |result: String| { | ||
assert_eq!( | ||
result, | ||
huge_response_test_json(), | ||
"Response does not exactly match the expected response", | ||
); | ||
server.close(); | ||
}); | ||
} | ||
|
||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we parametrize the nr of threads/loops so we can do
mpsc::channel(TEST_THRDS * TEST_ITERS);
?