MatrixAI / Polykey-CLI

Polykey CLI - Open Source Decentralized Secret Sharing System for Zero Trust Workflows
https://polykey.com
GNU General Public License v3.0
6 stars 3 forks source link

Remove any non-deterministic use of `sleep()` in tests #38

Open tegefaulkes opened 1 year ago

tegefaulkes commented 1 year ago

Specification

We need to remove any non-deterministic use of sleep() in tests. Most if not all of these will be sleeps waiting for key change propagation to happen.

To address this we need some way of knowing that the keys have finished changing. https://github.com/MatrixAI/Polykey/issues/594 addresses this in Polykey, but we need a change here.

The keys renew and reset commands need to wait for key changes to fully propagate before ending. This will be updated in the client handlers on Polykey.

Additional context

Tasks

  1. Remove any usage of sleep() waiting for keys changes and replace it with waiting for an event.
CMCDragonkai commented 1 year ago

Some uses of sleep is to simulate time passing. However generally anything that relies on time should parameterise it so that the caller can pass in what it wants the time to be. This is a good practice not only for testing, but also for ensuring a bunch of operations is recorded with the same time.

CMCDragonkai commented 1 year ago

That parameter can default to the now though for convenience. Removed a bunch of sleeps from NodeGraph.test.ts would reduce testing time by a significant amount. 80%