Moving the arc tests into arc.rs.
This commit is contained in:
parent
aa2efc05ea
commit
5e35d49a50
2 changed files with 31 additions and 28 deletions
|
@ -106,3 +106,34 @@ fn get_arc<T: send const>(c: comm::chan<proto<T>>) -> arc::arc<T> {
|
||||||
c.send(shared_get(chan(p)));
|
c.send(shared_get(chan(p)));
|
||||||
p.recv()
|
p.recv()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
import comm::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn manually_share_arc() {
|
||||||
|
let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||||
|
let arc_v = arc::arc(v);
|
||||||
|
|
||||||
|
let p = port();
|
||||||
|
let c = chan(p);
|
||||||
|
|
||||||
|
task::spawn() {||
|
||||||
|
let p = port();
|
||||||
|
c.send(chan(p));
|
||||||
|
|
||||||
|
let arc_v = p.recv();
|
||||||
|
|
||||||
|
let v = *arc::get::<[int]>(&arc_v);
|
||||||
|
assert v[3] == 4;
|
||||||
|
};
|
||||||
|
|
||||||
|
let c = p.recv();
|
||||||
|
c.send(arc::clone(&arc_v));
|
||||||
|
|
||||||
|
assert (*arc::get(&arc_v))[2] == 3;
|
||||||
|
|
||||||
|
log(info, arc_v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
use std;
|
|
||||||
import std::arc;
|
|
||||||
import comm::*;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
||||||
let arc_v = arc::arc(v);
|
|
||||||
|
|
||||||
let p = port();
|
|
||||||
let c = chan(p);
|
|
||||||
|
|
||||||
task::spawn() {||
|
|
||||||
let p = port();
|
|
||||||
c.send(chan(p));
|
|
||||||
|
|
||||||
let arc_v = p.recv();
|
|
||||||
|
|
||||||
let v = *arc::get::<[int]>(&arc_v);
|
|
||||||
assert v[3] == 4;
|
|
||||||
};
|
|
||||||
|
|
||||||
let c = p.recv();
|
|
||||||
c.send(arc::clone(&arc_v));
|
|
||||||
|
|
||||||
assert (*arc::get(&arc_v))[2] == 3;
|
|
||||||
|
|
||||||
log(info, arc_v);
|
|
||||||
}
|
|
Loading…
Reference in a new issue