Skip to content

Commit f76de93

Browse files
Copilotxperiandri
andauthored
Make concurrent cache test actually run in parallel
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/95956635-01ea-45da-a2fc-e89c2faafbbd Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
1 parent a89e07c commit f76de93

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

tests/FSharp.Data.GraphQL.Tests/ValidationCacheTests.fs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,21 @@ let ``MemoryValidationResultCache handles concurrent access`` () : Task = task {
132132
let key = { DocumentId = "doc1"; SchemaId = 1 }
133133

134134
// Call cache from multiple threads simultaneously
135-
let! results =
136-
[| 1..10 |]
137-
|> Seq.map (fun _ -> task { return cache.GetOrAdd producer key })
138-
|> Task.WhenAll
135+
let workerCount = 10
136+
use ready = CountdownEvent workerCount
137+
use startGate = new ManualResetEventSlim false
138+
139+
let workers =
140+
[| 1..workerCount |]
141+
|> Seq.map (fun _ ->
142+
Task.Run (fun () ->
143+
ready.Signal () |> ignore
144+
startGate.Wait ()
145+
cache.GetOrAdd producer key))
146+
147+
ready.Wait ()
148+
startGate.Set ()
149+
let! results = workers |> Task.WhenAll
139150

140151
// All results should be Success
141152
results |> Array.iter (fun r -> equals Success r)

0 commit comments

Comments
 (0)