Skip to content

Commit 398c17a

Browse files
committed
Simplified cache test
1 parent ce57938 commit 398c17a

1 file changed

Lines changed: 5 additions & 16 deletions

File tree

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ let ``MemoryValidationResultCache caches error results`` () =
121121
| Success -> fail "Expected ValidationError"
122122

123123
[<Fact>]
124-
let ``MemoryValidationResultCache handles concurrent access`` () : Task = task {
124+
let ``MemoryValidationResultCache handles concurrent access`` () =
125125
let cache = MemoryValidationResultCache () :> IValidationResultCache
126126
let mutable callCount = 0
127127
let producer () =
@@ -131,26 +131,15 @@ let ``MemoryValidationResultCache handles concurrent access`` () : Task = task {
131131

132132
let key = { DocumentId = "doc1"; SchemaId = 1 }
133133

134-
// Call cache from multiple threads simultaneously
135134
let workerCount = 10
136-
use workersReadyGate = new CountdownEvent (workerCount)
137-
use startGate = new ManualResetEventSlim (false)
135+
let results = Array.zeroCreate workerCount
138136

139-
let workers =
140-
[| 1..workerCount |]
141-
|> Array.map (fun _ ->
142-
Task.Run (fun () ->
143-
workersReadyGate.Signal () |> ignore
144-
startGate.Wait ()
145-
cache.GetOrAdd producer key))
146-
147-
workersReadyGate.Wait ()
148-
startGate.Set ()
149-
let! results = workers |> Task.WhenAll
137+
Parallel.For (0, workerCount, fun i ->
138+
results.[i] <- cache.GetOrAdd producer key
139+
) |> ignore
150140

151141
// All results should be Success
152142
results |> Array.iter (fun r -> equals Success r)
153143

154144
// Producer should be called at least once, but can run up to workerCount times due to ConcurrentDictionary.GetOrAdd factory semantics.
155145
Assert.True (callCount >= 1 && callCount <= workerCount, $"Expected callCount between 1 and {workerCount}, got {callCount}")
156-
}

0 commit comments

Comments
 (0)