@@ -61,7 +61,7 @@ let ``Basics``() =
6161    let  groups  =  eventLog |>  Seq.groupBy snd |>  Seq.toList
6262    Assert.Equal( 3 ,  groups.Length) 
6363    for  key,  events in  groups do 
64-         Assert.Equal< Set<( JobEvent *  int)>>( Set [  Started,  key;  Finished,  key ],  Set events) 
64+         Assert.Equal< Set<( JobEvent *  int)>>( Set [  Requested ,  key ;   Started,  key;  Finished,  key ],  Set events) 
6565
6666[<Fact>] 
6767let  ``We can cancel a job``  ()  = 
@@ -96,9 +96,14 @@ let ``We can cancel a job`` () =
9696        waitFor jobStarted
9797        jobStarted.Reset()  |>  ignore
9898
99+         let  jobRequested  =  new  ManualResetEvent( false ) 
100+         memoize.OnEvent( fun   ( e ,  _ )  ->   if  e =  Requested then  jobRequested.Set()  |>  ignore) 
101+ 
99102        let  _task2  =  NodeCode.StartAsTask_ ForTesting(  memoize.Get'( key,  computation ignore),  ct =  cts2.Token) 
100103        let  _task3  =  NodeCode.StartAsTask_ ForTesting(  memoize.Get'( key,  computation ignore),  ct =  cts3.Token) 
101104
105+         waitFor jobRequested
106+ 
102107        cts1.Cancel() 
103108        cts2.Cancel() 
104109
@@ -108,7 +113,14 @@ let ``We can cancel a job`` () =
108113
109114        waitFor jobCanceled
110115
111-         Assert.Equal<( JobEvent *  int)  array>([|  Started,  key;  Started,  key;  Canceled,  key |],  eventLog |>  Seq.toArray ) 
116+         Assert.Equal<( JobEvent *  int)  array>([| 
117+             Requested,  key
118+             Started,  key
119+             Requested,  key
120+             Requested,  key
121+             Restarted,  key
122+             Canceled,  key
123+         |],  eventLog |>  Seq.toArray ) 
112124    } 
113125
114126[<Fact>] 
@@ -139,22 +151,31 @@ let ``Job is restarted if first requestor cancels`` () =
139151        waitFor jobStarted
140152        jobStarted.Reset()  |>  ignore
141153
154+         let  jobRequested  =  new  ManualResetEvent( false ) 
155+         memoize.OnEvent( fun   ( e ,  _ )  ->   if  e =  Requested then  jobRequested.Set()  |>  ignore) 
156+ 
142157        let  _task2  =  NodeCode.StartAsTask_ ForTesting(  memoize.Get'( key,  computation key),  ct =  cts2.Token) 
143158        let  _task3  =  NodeCode.StartAsTask_ ForTesting(  memoize.Get'( key,  computation key),  ct =  cts3.Token) 
144159
160+         waitFor jobRequested
161+ 
145162        cts1.Cancel() 
146163
147164        waitFor jobStarted
148165
149-         cts3.Cancel() 
150- 
151166        jobCanComplete.Set()  |>  ignore
152167
153168        let!  result  =  _ task2
154169        Assert.Equal( 2 ,  result) 
155170
156171        let  orderedLog  =  eventLog |>  Seq.rev |>  Seq.toList
157-         let  expected  =  [  Started,  key;  Started,  key;  Finished,  key ] 
172+         let  expected  =  [ 
173+             Requested,  key
174+             Started,  key
175+             Requested,  key
176+             Requested,  key
177+             Restarted,  key
178+             Finished,  key ] 
158179
159180        Assert.Equal<_  list>( expected,  orderedLog) 
160181    } 
@@ -184,15 +205,20 @@ let ``Job is restarted if first requestor cancels but keeps running if second re
184205
185206        let  _task1  =  NodeCode.StartAsTask_ ForTesting(  memoize.Get'( key,  computation key),  ct =  cts1.Token) 
186207
187-         jobStarted.WaitOne ()   |>  ignore 
208+         waitFor jobStarted 
188209        jobStarted.Reset()  |>  ignore
189210
211+         let  jobRequested  =  new  ManualResetEvent( false ) 
212+         memoize.OnEvent( fun   ( e ,  _ )  ->   if  e =  Requested then  jobRequested.Set()  |>  ignore) 
213+ 
190214        let  _task2  =  NodeCode.StartAsTask_ ForTesting(  memoize.Get'( key,  computation key),  ct =  cts2.Token) 
191215        let  _task3  =  NodeCode.StartAsTask_ ForTesting(  memoize.Get'( key,  computation key),  ct =  cts3.Token) 
192216
217+         waitFor jobRequested
218+ 
193219        cts1.Cancel() 
194220
195-         jobStarted.WaitOne ()   |>  ignore 
221+         waitFor jobStarted 
196222
197223        cts2.Cancel() 
198224
@@ -202,7 +228,13 @@ let ``Job is restarted if first requestor cancels but keeps running if second re
202228        Assert.Equal( 2 ,  result) 
203229
204230        let  orderedLog  =  eventLog |>  Seq.rev |>  Seq.toList
205-         let  expected  =  [  Started,  key;  Started,  key;  Finished,  key ] 
231+         let  expected  =  [ 
232+             Requested,  key
233+             Started,  key
234+             Requested,  key
235+             Requested,  key
236+             Restarted,  key
237+             Finished,  key ] 
206238
207239        Assert.Equal<_  list>( expected,  orderedLog) 
208240    } 
@@ -228,7 +260,7 @@ let ``Stress test`` () =
228260    let  keyCount  =  rng.Next( 5 ,  200 ) 
229261    let  keys  =  [|  1  ..  keyCount |] 
230262
231-     let  testTimeoutMs  =  threads *  iterations *  maxDuration
263+     let  testTimeoutMs  =  threads *  iterations *  maxDuration  *   2 
232264
233265    let  intenseComputation  durationMs result  = 
234266        async  { 
0 commit comments