Auto merge of #12268 - izgzhen:fm-spawn, r=Manishearth

Spawn threads for requests in file manager

r? @Manishearth

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] There are tests for these changes OR

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12268)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-07-08 20:33:26 -07:00 committed by GitHub
commit c2a22bd05e
6 changed files with 217 additions and 164 deletions

View file

@ -41,7 +41,7 @@ fn test_filemanager() {
// Try to select a dummy file "tests/unit/net/test.txt"
let (tx, rx) = ipc::channel().unwrap();
chan.send(FileManagerThreadMsg::SelectFile(patterns.clone(), tx, origin.clone())).unwrap();
let selected = rx.recv().expect("File manager channel is broken")
let selected = rx.recv().expect("Broken channel")
.expect("The file manager failed to find test.txt");
// Expecting attributes conforming the spec
@ -53,21 +53,27 @@ fn test_filemanager() {
let (tx2, rx2) = ipc::channel().unwrap();
chan.send(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), origin.clone())).unwrap();
let msg = rx2.recv().expect("File manager channel is broken");
let msg = rx2.recv().expect("Broken channel");
let vec = msg.expect("File manager reading failure is unexpected");
assert!(test_file_content == vec, "Read content differs");
}
// Delete the id
chan.send(FileManagerThreadMsg::DecRef(selected.id.clone(), origin.clone())).unwrap();
{
let (tx2, rx2) = ipc::channel().unwrap();
chan.send(FileManagerThreadMsg::DecRef(selected.id.clone(), origin.clone(), tx2)).unwrap();
let ret = rx2.recv().expect("Broken channel");
assert!(ret.is_ok(), "DecRef is not okay");
}
// Test by reading again, expecting read error because we invalidated the id
{
let (tx2, rx2) = ipc::channel().unwrap();
chan.send(FileManagerThreadMsg::ReadFile(tx2, selected.id.clone(), origin.clone())).unwrap();
let msg = rx2.recv().expect("File manager channel is broken");
let msg = rx2.recv().expect("Broken channel");
match msg {
Err(FileManagerThreadError::ReadFileError) => {},