Skip to content

Commit

Permalink
Adding test case for #687.
Browse files Browse the repository at this point in the history
The test no longer repros after a lot of my recent channel work.

Closes #687.
  • Loading branch information
Eric Holk committed Jul 22, 2011
1 parent 54be5b0 commit 4a6ccf3
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/test/run-pass/issue-687.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// xfail-stage0

use std;
import std::ivec;

tag msg {
closed;
received(u8[]);
}

fn producer(chan[u8[]] c) {
c <| ~[1u8, 2u8, 3u8, 4u8];
let u8[] empty = ~[];
c <| empty;
}

fn packager(chan[chan[u8[]]] cb, chan[msg] msg) {
let port[u8[]] p = port();
cb <| chan(p);
while (true) {
log "waiting for bytes";
let u8[] data;
p |> data;
log "got bytes";
if (ivec::len[u8](data) == 0u) {
log "got empty bytes, quitting";
break;
}
log "sending non-empty buffer of length";
log ivec::len[u8](data);
msg <| received(data);
log "sent non-empty buffer";
}
log "sending closed message";
msg <| closed;
log "sent closed message";
}

fn main() {
let port[msg] p = port();
let port[chan[u8[]]] recv_reader = port();
auto pack = spawn packager(chan(recv_reader), chan(p));

let chan[u8[]] source_chan;
recv_reader |> source_chan;
let task prod = spawn producer(source_chan);

while (true) {
let msg msg;
p |> msg;
alt (msg) {
case (closed) {
log "Got close message";
break;
}
case (received(?data)) {
log "Got data. Length is:";
log ivec::len[u8](data);
}
}
}
}

0 comments on commit 4a6ccf3

Please sign in to comment.