From a3bf3c96e5f85cea5fa2f53feb60eaeb8b7b1868 Mon Sep 17 00:00:00 2001 From: Jakub Majocha <1760221+majocha@users.noreply.github.com> Date: Mon, 27 Jan 2025 11:09:45 +0100 Subject: [PATCH 1/3] Tests: Fix flaky `AssemblyVersion` tests (#18268) --- DEVGUIDE.md | 10 ++++++ .../AttributeUsage/AttributeUsage.fs | 32 ++++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/DEVGUIDE.md b/DEVGUIDE.md index 2ca137ba100..28b511fac04 100644 --- a/DEVGUIDE.md +++ b/DEVGUIDE.md @@ -243,6 +243,16 @@ or > Please note, that by default, **Release** version of IL baseline tests will be running in CI, so when updating baseline (.bsl) files, make sure to add `-c Release` flag to the build command. +### Parallel execution of tests + +Tests utilizing xUnit framework by default run in parallel. If your tests depend on some shared state or are time-critical, you can add the module to predefined `NotThreadSafeResourceCollection` to prevent parallel execution. +For example: +```fsharp +[] +module TimeCritical = +``` + + ### Updating FCS surface area baselines ```bash diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs index 9b7cdc5a053..a28d6175642 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/AttributeUsage/AttributeUsage.fs @@ -34,21 +34,23 @@ module CustomAttributes_AttributeUsage = |> verifyCompileAndRun |> shouldSucceed - // SOURCE=AssemblyVersion03.fs # AssemblyVersion03.fs - [] - let ``AssemblyVersion03_fs`` compilation = - compilation - |> withOptions ["--nowarn:52"] - |> verifyCompileAndRun - |> shouldSucceed - - // SOURCE=AssemblyVersion04.fs # AssemblyVersion04.fs - [] - let ``AssemblyVersion04_fs`` compilation = - compilation - |> withOptions ["--nowarn:52"] - |> verifyCompileAndRun - |> shouldSucceed + [] + module TimeCritical = + // SOURCE=AssemblyVersion03.fs # AssemblyVersion03.fs + [] + let ``AssemblyVersion03_fs`` compilation = + compilation + |> withOptions ["--nowarn:52"] + |> verifyCompileAndRun + |> shouldSucceed + + // SOURCE=AssemblyVersion04.fs # AssemblyVersion04.fs + [] + let ``AssemblyVersion04_fs`` compilation = + compilation + |> withOptions ["--nowarn:52"] + |> verifyCompileAndRun + |> shouldSucceed // SOURCE=AttributeTargetsIsCtor01.fs # AttributeTargetsIsCtor01.fs [] From 013c9982b7d1de552975f4efee71ccfdde98aed6 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Mon, 27 Jan 2025 05:11:06 -0500 Subject: [PATCH 2/3] =?UTF-8?q?Replace=20internal=20option=E2=80=93voption?= =?UTF-8?q?=20conversions=20with=20FSharp.Core=20funcs=20(#18269)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Compiler/Service/IncrementalBuild.fs | 5 ----- src/Compiler/TypedTree/TypedTree.fs | 6 +++--- src/Compiler/TypedTree/TypedTreeOps.fs | 6 +++--- src/Compiler/Utilities/illib.fs | 12 ------------ src/Compiler/Utilities/illib.fsi | 6 ------ .../src/FSharp.Editor/Common/Extensions.fs | 13 ------------- .../CodeFixes/CodeFixTestFramework.fs | 10 ---------- 7 files changed, 6 insertions(+), 52 deletions(-) diff --git a/src/Compiler/Service/IncrementalBuild.fs b/src/Compiler/Service/IncrementalBuild.fs index 872b27fdcd9..0cdc4b9235e 100644 --- a/src/Compiler/Service/IncrementalBuild.fs +++ b/src/Compiler/Service/IncrementalBuild.fs @@ -229,11 +229,6 @@ type TcInfoExtras = member x.TcSymbolUses = x.tcSymbolUses -module ValueOption = - let toOption = function - | ValueSome x -> Some x - | _ -> None - type private SingleFileDiagnostics = (PhasedDiagnostic * FSharpDiagnosticSeverity) array type private TypeCheck = TcInfo * TcResultsSinkImpl * CheckedImplFile option * string * SingleFileDiagnostics diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index 11ff117cc25..d2af320b8de 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -2122,7 +2122,7 @@ type ModuleOrNamespaceType(kind: ModuleOrNamespaceKind, vals: QueueList, en |> List.tryFind (fun v -> match key.TypeForLinkage with | None -> true | Some keyTy -> ccu.MemberSignatureEquality(keyTy, v.Type)) - |> ValueOptionInternal.ofOption + |> ValueOption.ofOption /// Get a table of values indexed by logical name member _.AllValsByLogicalName = @@ -4237,7 +4237,7 @@ type UnionCaseRef = /// Try to dereference the reference member x.TryUnionCase = x.TyconRef.TryDeref - |> ValueOptionInternal.bind (fun tcref -> tcref.GetUnionCaseByName x.CaseName |> ValueOptionInternal.ofOption) + |> ValueOption.bind (fun tcref -> tcref.GetUnionCaseByName x.CaseName |> ValueOption.ofOption) /// Get the attributes associated with the union case member x.Attribs = x.UnionCase.Attribs @@ -4300,7 +4300,7 @@ type RecdFieldRef = /// Try to dereference the reference member x.TryRecdField = x.TyconRef.TryDeref - |> ValueOptionInternal.bind (fun tcref -> tcref.GetFieldByName x.FieldName |> ValueOptionInternal.ofOption) + |> ValueOption.bind (fun tcref -> tcref.GetFieldByName x.FieldName |> ValueOption.ofOption) /// Get the attributes associated with the compiled property of the record field member x.PropertyAttribs = x.RecdField.PropertyAttribs diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index d4f58881b19..909d6f437a8 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -3526,11 +3526,11 @@ let IsMatchingFSharpAttributeOpt g attrOpt (Attrib(tcref2, _, _, _, _, _, _)) = [] let (|ExtractAttribNamedArg|_|) nm args = - args |> List.tryPick (function AttribNamedArg(nm2, _, _, v) when nm = nm2 -> Some v | _ -> None) |> ValueOptionInternal.ofOption - + args |> List.tryPick (function AttribNamedArg(nm2, _, _, v) when nm = nm2 -> Some v | _ -> None) |> ValueOption.ofOption + [] let (|ExtractILAttributeNamedArg|_|) nm (args: ILAttributeNamedArg list) = - args |> List.tryPick (function nm2, _, _, v when nm = nm2 -> Some v | _ -> None) |> ValueOptionInternal.ofOption + args |> List.tryPick (function nm2, _, _, v when nm = nm2 -> Some v | _ -> None) |> ValueOption.ofOption [] let (|StringExpr|_|) = function Expr.Const (Const.String n, _, _) -> ValueSome n | _ -> ValueNone diff --git a/src/Compiler/Utilities/illib.fs b/src/Compiler/Utilities/illib.fs index e09c650e39b..5e32e3b8699 100644 --- a/src/Compiler/Utilities/illib.fs +++ b/src/Compiler/Utilities/illib.fs @@ -715,18 +715,6 @@ module Span = state -module ValueOptionInternal = - - let inline ofOption x = - match x with - | Some x -> ValueSome x - | None -> ValueNone - - let inline bind ([] f) x = - match x with - | ValueSome x -> f x - | ValueNone -> ValueNone - module String = let make (n: int) (c: char) : string = String(c, n) diff --git a/src/Compiler/Utilities/illib.fsi b/src/Compiler/Utilities/illib.fsi index be4edea38f9..03525593188 100644 --- a/src/Compiler/Utilities/illib.fsi +++ b/src/Compiler/Utilities/illib.fsi @@ -243,12 +243,6 @@ module internal ResizeArray = module internal Span = val inline exists: predicate: ('T -> bool) -> span: Span<'T> -> bool -module internal ValueOptionInternal = - - val inline ofOption: x: 'a option -> 'a voption - - val inline bind: f: ('a -> 'b voption) -> x: 'a voption -> 'b voption - module internal String = val make: n: int -> c: char -> string diff --git a/vsintegration/src/FSharp.Editor/Common/Extensions.fs b/vsintegration/src/FSharp.Editor/Common/Extensions.fs index b0eb7305713..5b154deab73 100644 --- a/vsintegration/src/FSharp.Editor/Common/Extensions.fs +++ b/vsintegration/src/FSharp.Editor/Common/Extensions.fs @@ -327,19 +327,6 @@ module Option = else None -[] -module ValueOption = - - let inline ofOption o = - match o with - | Some v -> ValueSome v - | _ -> ValueNone - - let inline toOption o = - match o with - | ValueSome v -> Some v - | _ -> None - [] module IEnumerator = let chooseV f (e: IEnumerator<'T>) = diff --git a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/CodeFixTestFramework.fs b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/CodeFixTestFramework.fs index 55920c294ed..d5f2dbd3988 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/CodeFixTestFramework.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/CodeFixTestFramework.fs @@ -33,16 +33,6 @@ type Mode = | WithSettings of CodeFixesOptions module ValueOption = - let inline toOption o = - match o with - | ValueSome v -> Some v - | _ -> None - - let inline ofOption o = - match o with - | Some v -> ValueSome v - | _ -> ValueNone - let inline either f y o = match o with | ValueSome v -> f v From 06e27edfc2766184f44df0b83f7b0debd6560627 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Mon, 27 Jan 2025 05:11:56 -0500 Subject: [PATCH 3/3] Add reminder to check /.dotnet dir when tests fail to find SDK (#18271) --- tests/FSharp.Test.Utilities/Utilities.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FSharp.Test.Utilities/Utilities.fs b/tests/FSharp.Test.Utilities/Utilities.fs index f48c0eac880..fec1da0895c 100644 --- a/tests/FSharp.Test.Utilities/Utilities.fs +++ b/tests/FSharp.Test.Utilities/Utilities.fs @@ -239,7 +239,7 @@ let main argv = 0""" Project directory: %s{projectDirectory} STDOUT: %s{output} STDERR: %s{errors} -An error occurred getting netcoreapp references: %A{e} +An error occurred getting netcoreapp references (compare the output of `dotnet --list-sdks` and/or the contents of the local `/.dotnet` directory against what is in `global.json`): %A{e} """ raise (Exception (message, e)) finally