Skip to content

Commit 94e6c73

Browse files
T-Grogithub-actions
authored andcommitted
Avoid xunit catastrophic failure caused by testcollection ID
1 parent fa593f3 commit 94e6c73

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tests/FSharp.Test.Utilities/XunitHelpers.fs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,21 @@ module TestCaseCustomizations =
7777
let oldTestClass = oldTestMethod.TestClass
7878
let oldTestCollection = oldTestMethod.TestClass.TestCollection
7979

80+
// Create a DETERMINISTIC collection ID based on the test case's unique ID
81+
// This ensures the same test case always gets the same collection ID
82+
let collectionId =
83+
use sha = System.Security.Cryptography.SHA256.Create()
84+
let bytes = System.Text.Encoding.UTF8.GetBytes(testCase.UniqueID)
85+
let hash = sha.ComputeHash(bytes)
86+
System.Guid(hash.[0..15]) // Take first 16 bytes for GUID
87+
8088
// Create a new collection with a unique id for the test case.
8189
let newTestCollection =
8290
new TestCollection(
8391
oldTestCollection.TestAssembly,
8492
oldTestCollection.CollectionDefinition,
8593
oldTestCollection.DisplayName,
86-
Guid.NewGuid()
94+
collectionId
8795
)
8896

8997
let newTestClass = new TestClass(newTestCollection, oldTestClass.Class)

0 commit comments

Comments
 (0)