Skip to content

Commit

Permalink
Add env methods to wait for a specified number of listeners on a channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Norman authored and matthias-wende-sociomantic committed Oct 30, 2018
1 parent a65ee5e commit 00c85b4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
10 changes: 10 additions & 0 deletions relnotes/expectlisteners.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### New method to wait until a certain number of listeners are registered

`turtle.env.Dht`

App test suites typically need to wait for mirror/listen requests to start
before running any tests. To support this, the new method `Dht.expectListeners`
provides a means for waiting until a specified number of listeners are
registered with a specified list of channels. This allows app test suites to
implement test cases which would validate the mirror setup.

56 changes: 56 additions & 0 deletions src/turtle/env/Dht.d
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,62 @@ public class Dht : Node!(DhtNode, "dht")
));
}

/***************************************************************************
Waits until the specified number of listeners are registered with the
specified channel.
Params:
channel = DHT channel to lookup
expected_listeners = number of listeners to wait for
timeout = limit of time to wait (seconds)
check_interval = how often to poll for changes (seconds)
Throws:
TestException if timeout has been hit
***************************************************************************/

public void expectListeners ( cstring channel, uint expected_listeners,
double timeout = 1.0, double check_interval = 0.05 )
{
this.expectListeners((&channel)[0..1], expected_listeners, timeout,
check_interval);
}

/***************************************************************************
Waits until the specified number of listeners are registered with the
specified channels.
Params:
channels = DHT channels to lookup
expected_listeners = number of listeners to wait for per channel
timeout = limit of time to wait (seconds)
check_interval = how often to poll for changes (seconds)
Throws:
TestException if timeout has been hit
***************************************************************************/

public void expectListeners ( cstring[] channels, uint expected_listeners,
double timeout = 1.0, double check_interval = 0.05 )
{
this.waitForCondition(timeout, check_interval,
{
foreach ( c; channels )
{
auto channel = global_storage.getCreate(c);
if ( channel.registered_listeners != expected_listeners )
return false;
}
return true;
},
.format("Expected number of listeners on channels '{}' not reached" ~
"after {} seconds", channels, timeout)
);
}

/***************************************************************************
Expand Down

0 comments on commit 00c85b4

Please sign in to comment.