@@ -7,22 +7,25 @@ import Time, {TimeUnits} from "../retries/Time";
77import { getMockTestCluster } from "../test/fixtures/ClusterFixtures" ;
88import { ClusterInfo } from "../apis/clusters" ;
99import { TokenFixture } from "../test/fixtures/TokenFixtures" ;
10- import { RetryConfigs } from "../retries/retries " ;
10+ import FakeTimers from "@sinonjs/fake-timers " ;
1111
1212describe ( __filename , function ( ) {
1313 this . timeout ( new Time ( 10 , TimeUnits . minutes ) . toMillSeconds ( ) . value ) ;
1414
1515 let mockedClient : ApiClient ;
1616 let mockedCluster : Cluster ;
1717 let testClusterDetails : ClusterInfo ;
18+ let fakeTimer : FakeTimers . InstalledClock ;
1819
1920 beforeEach ( async ( ) => {
2021 ( { mockedCluster, mockedClient, testClusterDetails} =
2122 await getMockTestCluster ( ) ) ;
2223
23- RetryConfigs . waitTime = ( ) => {
24- return new Time ( 0 , TimeUnits . milliseconds ) ;
25- } ;
24+ fakeTimer = FakeTimers . install ( ) ;
25+ } ) ;
26+
27+ afterEach ( ( ) => {
28+ fakeTimer . uninstall ( ) ;
2629 } ) ;
2730
2831 it ( "calling start on a non terminated state should not throw an error" , async ( ) => {
@@ -65,7 +68,9 @@ describe(__filename, function () {
6568 await mockedCluster . refresh ( ) ;
6669 assert . notEqual ( mockedCluster . state , "RUNNING" ) ;
6770
68- await mockedCluster . start ( ) ;
71+ const startPromise = mockedCluster . start ( ) ;
72+ await fakeTimer . runToLastAsync ( ) ;
73+ await startPromise ;
6974 assert . equal ( mockedCluster . state , "RUNNING" ) ;
7075
7176 verify (
@@ -125,7 +130,10 @@ describe(__filename, function () {
125130
126131 assert . equal ( mockedCluster . state , "RUNNING" ) ;
127132
128- await mockedCluster . stop ( ) ;
133+ const stopPromise = mockedCluster . stop ( ) ;
134+ await fakeTimer . runToLastAsync ( ) ;
135+ await stopPromise ;
136+
129137 assert . equal ( mockedCluster . state , "TERMINATED" ) ;
130138
131139 verify (
@@ -175,7 +183,10 @@ describe(__filename, function () {
175183 await mockedCluster . refresh ( ) ;
176184 assert . notEqual ( mockedCluster . state , "RUNNING" ) ;
177185
178- await mockedCluster . stop ( ) ;
186+ const stopPromise = mockedCluster . stop ( ) ;
187+ await fakeTimer . runToLastAsync ( ) ;
188+ await stopPromise ;
189+
179190 assert . equal ( mockedCluster . state , "TERMINATED" ) ;
180191
181192 verify (
@@ -243,7 +254,9 @@ describe(__filename, function () {
243254 await mockedCluster . refresh ( ) ;
244255
245256 assert . equal ( mockedCluster . state , "PENDING" ) ;
246- await mockedCluster . start ( instance ( token ) ) ;
257+ const startPromise = mockedCluster . start ( instance ( token ) ) ;
258+ await fakeTimer . runToLastAsync ( ) ;
259+ await startPromise ;
247260
248261 verify ( token . isCancellationRequested ) . thrice ( ) ;
249262 } ) ;
0 commit comments