Skip to content

Commit

Permalink
Make tests tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Feb 27, 2025
1 parent 8b019e5 commit 9f99b41
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 121 deletions.
17 changes: 9 additions & 8 deletions test/Ionide.ProjInfo.Tests/TestAssets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,14 @@ let ``loader2-cancel-slow`` = {
"classlibf1"
/ "classlibf1.fsproj"
]
Expects = fun projectsAfterBuild -> ()
// Expect.equal (Seq.length projectsAfterBuild) 1 "projects count"

// let classlibf1 =
// projectsAfterBuild
// |> Seq.head
Expects = ignore
}

// Expect.equal classlibf1.SourceFiles.Length 3 "classlibf1 source files"
// Expect.equal classlibf1.TargetFramework "net8.0" "classlibf1 target framework"
let ``loader2-concurrent`` = {
ProjDir = "loader2-concurrent"
EntryPoints = [
"classlibf1"
/ "classlibf1.fsproj"
]
Expects = ignore
}
238 changes: 125 additions & 113 deletions test/Ionide.ProjInfo.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ open System.Threading.Tasks
open Microsoft.Build.Evaluation
open Ionide.ProjInfo.ProjectLoader

module Exception =
open System.Runtime.ExceptionServices

let inline reraiseAny (e: exn) =
ExceptionDispatchInfo.Capture(e).Throw()

let RepoDir =
(__SOURCE_DIRECTORY__
/ ".."
Expand Down Expand Up @@ -1469,50 +1475,51 @@ let testWithEnv name (data: TestAssetProjInfo2) f test =
test
name
(fun () ->
task {
let logger = Log.create (sprintf "Test '%s'" name)
let fs = FileUtils logger

let logger = Log.create (sprintf "Test '%s'" name)
let fs = FileUtils logger
let testDir = inDir fs data.ProjDir
copyDirFromAssets fs data.ProjDir testDir

let testDir = inDir fs data.ProjDir
copyDirFromAssets fs data.ProjDir testDir
let entrypoints =
data.EntryPoints
|> Seq.map (fun x ->
testDir
/ x
)

let entrypoints =
data.EntryPoints
|> Seq.map (fun x ->
testDir
/ x
entrypoints
|> Seq.iter (fun x ->
dotnet fs [
"restore"
x
]
|> checkExitCodeZero
)

entrypoints
|> Seq.iter (fun x ->
dotnet fs [
"restore"
x
]
|> checkExitCodeZero
)

let binlog = new FileInfo(Path.Combine(testDir, $"{name}.binlog"))
use blc = new Binlogs(binlog)
let binlog = new FileInfo(Path.Combine(testDir, $"{name}.binlog"))
use blc = new Binlogs(binlog)

let env = {
Logger = logger
FS = fs
Binlog = blc
Data = data
Entrypoints = entrypoints
}
let env = {
Logger = logger
FS = fs
Binlog = blc
Data = data
Entrypoints = entrypoints
}

try
f env
with e ->
try
do! f env
with e ->

logger.error (
Message.eventX "binlog path {binlog}"
>> Message.setField "binlog" binlog.FullName
)
logger.error (
Message.eventX "binlog path {binlog}"
>> Message.setField "binlog" binlog.FullName
)

reraise ()
Exception.reraiseAny e
}
)

let projectCollection () =
Expand All @@ -1531,119 +1538,124 @@ type IWorkspaceLoader2 =


let buildManagerSessionTests toolsPath =
testSequenced
<| ftestList "buildManagerSessionTests" [
testCase
ftestList "buildManagerSessionTests" [
testCaseTask
|> testWithEnv
"loader2-solution-with-2-projects"
``loader2-solution-with-2-projects``
(fun env ->
task {

let path =
env.Entrypoints
|> Seq.map ProjectGraphEntryPoint
let path =
env.Entrypoints
|> Seq.map ProjectGraphEntryPoint

let loggers = env.Binlog.Loggers
let loggers = env.Binlog.Loggers

// Evaluation
use pc = projectCollection ()
let graph = ProjectLoader2.EvaluateAsGraphDesignTime(path, pc)
// Evaluation
use pc = projectCollection ()
let graph = ProjectLoader2.EvaluateAsGraphDesignTime(path, pc)

// Execution
let bp = BuildParameters(Loggers = loggers)
// Execution
let bp = BuildParameters(Loggers = loggers)

let bm = new BuildManagerSession(buildParameters = bp)
let bm = new BuildManagerSession(buildParameters = bp)

let result =
ProjectLoader2.Execution(bm, graph)
|> Task.RunSynchronously
let result =
ProjectLoader2.Execution(bm, graph)
|> Task.RunSynchronously

// Parse
let projectsAfterBuild =
ProjectLoader2.Parse result
|> Seq.choose (
function
| Ok(Ok(LoadedProjectInfo.StandardProjectInfo x)) -> Some x
| _ -> None
)
// Parse
let projectsAfterBuild =
ProjectLoader2.Parse result
|> Seq.choose (
function
| Ok(Ok(LoadedProjectInfo.StandardProjectInfo x)) -> Some x
| _ -> None
)

env.Data.Expects projectsAfterBuild
env.Data.Expects projectsAfterBuild
}
)

testCase
testCaseTask
|> testWithEnv
"Concurrency - new graph every time"
``loader2-solution-with-2-projects``
``loader2-concurrent``
(fun env ->
let path =
env.Entrypoints
|> Seq.map ProjectGraphEntryPoint

use pc = projectCollection ()

let bp = BuildParameters(Loggers = env.Binlog.Loggers)

let bm = new BuildManagerSession(buildParameters = bp)

let work =
async {
// Evaluation
let graph = ProjectLoader2.EvaluateAsGraph(path, pc)
let! ct = Async.CancellationToken

// Execution
return!
ProjectLoader2.Execution(bm, graph, ct = ct)
|> Async.AwaitTask
}

// Should be throttled so concurrent builds won't fail
let result =
Async.Parallel [
work
work
work
work
]
task {
let path =
env.Entrypoints
|> Seq.map ProjectGraphEntryPoint

use pc = projectCollection ()

|> Async.RunSynchronously
let bp = BuildParameters(Loggers = env.Binlog.Loggers)

()
let bm = new BuildManagerSession(buildParameters = bp)

let work =
async {
// Evaluation
let graph = ProjectLoader2.EvaluateAsGraph(path, pc)
let! ct = Async.CancellationToken

// Execution
return!
ProjectLoader2.Execution(bm, graph, ct = ct)
|> Async.AwaitTask
}

// Should be throttled so concurrent builds won't fail
let result =
Async.Parallel [
work
work
work
work
]

|> Async.RunSynchronously

()

}
)


testCase
testCaseTask
|> testWithEnv
"Cancellable"
``loader2-cancel-slow``
(fun env ->
let path =
env.Entrypoints
|> Seq.map ProjectGraphEntryPoint
task {
let path =
env.Entrypoints
|> Seq.map ProjectGraphEntryPoint


// Evaluation
use pc = projectCollection ()
// Evaluation
use pc = projectCollection ()

let graph = ProjectLoader2.EvaluateAsGraph(path, pc)
let graph = ProjectLoader2.EvaluateAsGraph(path, pc)

// Execution
let bp = BuildParameters(Loggers = env.Binlog.Loggers)
let bm = new BuildManagerSession(buildParameters = bp)
// Execution
let bp = BuildParameters(Loggers = env.Binlog.Loggers)
let bm = new BuildManagerSession(buildParameters = bp)

try
use cts = new CancellationTokenSource()
cts.CancelAfter(TimeSpan.FromSeconds(1.))
try
use cts = new CancellationTokenSource()
cts.CancelAfter(TimeSpan.FromSeconds(1.))

let build = ProjectLoader2.Execution(bm, graph, ct = cts.Token)
let build = ProjectLoader2.Execution(bm, graph, ct = cts.Token)

Task.RunSynchronously build
|> ignore
with
| :? OperationCanceledException -> ()
| e -> reraise ()
Task.RunSynchronously build
|> ignore
with
| :? OperationCanceledException -> ()
| e -> Exception.reraiseAny e

}
)
]

Expand Down
5 changes: 5 additions & 0 deletions test/examples/loader2-concurrent/classlibf1/Library.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace classlibf1

module Say =
let hello name =
printfn "Hello %s" name
21 changes: 21 additions & 0 deletions test/examples/loader2-concurrent/classlibf1/classlibf1.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="Library.fs" />
</ItemGroup>

<Target Name="SleepTask" BeforeTargets="CoreCompile">
<Exec Command="powershell -Command &quot;Start-Sleep -Seconds 1&quot;"
Condition="'$(OS)' == 'Windows_NT'"
IgnoreExitCode="true" />
<Exec Command="sleep 1"
Condition="'$(OS)' != 'Windows_NT'"
IgnoreExitCode="true" />
</Target>

</Project>

0 comments on commit 9f99b41

Please sign in to comment.