Skip to content

Commit

Permalink
Fix race.exception.double unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
skoppe committed Sep 12, 2024
1 parent e32f924 commit b3a2ca3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 5 additions & 3 deletions source/concurrency/sender.d
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ auto toSenderObject(Sender)(Sender sender) if (models!(Sender, isSender)) {
/// A sender that always sets an error
struct ThrowingSender {
alias Value = void;
string msg = "ThrowingSender";
static struct Op(Receiver) {
string msg;
Receiver receiver;
@disable
this(ref return scope typeof(this) rhs);
Expand All @@ -339,14 +341,14 @@ struct ThrowingSender {
@disable void opAssign(typeof(this) rhs) nothrow @safe @nogc;
@disable void opAssign(ref typeof(this) rhs) nothrow @safe @nogc;

void start() {
receiver.setError(new Exception("ThrowingSender"));
void start() @trusted scope {
receiver.setError(new Exception(msg));
}
}

auto connect(Receiver)(return Receiver receiver) @safe return scope {
// ensure NRVO
auto op = Op!Receiver(receiver);
auto op = Op!Receiver(msg, receiver);
return op;
}
}
Expand Down
11 changes: 4 additions & 7 deletions tests/ut/concurrency/operations.d
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,11 @@ unittest {

@("race.exception.double") @safe
unittest {
auto slow = ThreadSender().then(() @trusted shared {
Thread.sleep(50.msecs);
throw new Exception("Slow");
});
auto fast = ThreadSender().then(() shared {
throw new Exception("Fast");
});
auto slow = ThrowingSender("Slow").via(delay(50.msecs));
auto fast = ThrowingSender("Fast");

race(slow, fast).syncWait.assumeOk.shouldThrowWithMessage("Fast");
race(fast, slow).syncWait.assumeOk.shouldThrowWithMessage("Fast");
}

@("race.cancel-other") @safe
Expand Down

0 comments on commit b3a2ca3

Please sign in to comment.