Skip to content

Link peer unit testing challenge -- timing #154

@jamshark70

Description

@jamshark70

Question rather than an issue --

I'm informally responsible for unit tests of SuperCollider's LinkClock. Most of the tests are fine.

We have one test called test_newLinkClock_shouldNotChangeLinkTempo.

  1. Create a LinkClock at 150 bpm.
  2. Wait 500 ms for the Link session to stabilize.
  3. Create a second LinkClock at 60 bpm.
  4. This should sync clock2's tempo (and phase etc., but tempo is what we're testing). On the SC side, this causes a \tempo notification to be broadcast, which signals the test to move ahead.
  5. Then we check if clock1's tempo is still 150 bpm: true = pass.
  6. Both clocks (peers) are then destroyed at the same time.

On my machine, if I run this test in isolation, it passes.

In our github CI, the test sporadically fails.

I can also reproduce the failure if I run the test multiple times in quick succession. When it fails, it looks like clock2 controls the Link session's tempo, despite being created later. But, if I increase the delay after creating the first clock, the failures disappear.

So there's a conflict between Link requiring some time to ensure that the session is created correctly vs the desire to minimize hardcoded delays in a unit testing suite that already takes longer to run than we might like.

So the question is how best to handle this.

Is there a recommendation for how long to wait for the first Link peer to stabilize the session, so that we can be sure of its state?

Or (better) does the Link API emit some signal when the session is ready to be trusted? Above, for instance, the second peer gets a tempo-change notification if, at connection time, its tempo disagrees with the session's established tempo. But the first peer, AFAICS, gets nothing. So, on our side, I don't know how to be sure that the clock has actually synced up with the session. Understood that, under normal use, you'd create the peer and probably start playing up to several minutes later -- but for testing purposes, it would really help not to have to hardcode long wait times.

Any advice welcome -- thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions