Skip to content

Commit

Permalink
Cancellable: remove UsingToken usages in tests (#18276)
Browse files Browse the repository at this point in the history
* Remove Cancellable.UsingToken from tests

The token is now always set inside the cancellable computation

* Release notes

---------

Co-authored-by: Kevin Ransom (msft) <[email protected]>
  • Loading branch information
auduchinok and KevinRansom authored Feb 4, 2025
1 parent bacc160 commit 1f9b0ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@

* FSharpCheckFileResults.ProjectContext.ProjectOptions will not be available when using the experimental Transparent Compiler feature. ([PR #18205](https://github.com/dotnet/fsharp/pull/18205))
* Update `Obsolete` attribute checking to account for `DiagnosticId` and `UrlFormat` properties. ([PR #18224](https://github.com/dotnet/fsharp/pull/18224))
* Remove `Cancellable.UsingToken` from tests ([PR #18276](https://github.com/dotnet/fsharp/pull/18276))

### Breaking Changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let mutable private wasCancelled = false
let runCancelFirstTime f =
let mutable requestCount = 0
fun () ->
use _ = Cancellable.UsingToken cts.Token
if requestCount = 0 then
cts.Cancel()

Expand Down Expand Up @@ -150,12 +149,17 @@ let referenceReaderProject getPreTypeDefs (cancelOnModuleAccess: bool) (options:
let parseAndCheck path source options =
cts <- new CancellationTokenSource()
wasCancelled <- false
use _ = Cancellable.UsingToken cts.Token

try
match Async.RunSynchronously(checker.ParseAndCheckFileInProject(path, 0, SourceText.ofString source, options), cancellationToken = cts.Token) with
| fileResults, FSharpCheckFileAnswer.Aborted -> None
| fileResults, FSharpCheckFileAnswer.Succeeded results -> Some results
let checkFileAsync = checker.ParseAndCheckFileInProject(path, 0, SourceText.ofString source, options)
let result =
match Async.RunSynchronously(checkFileAsync, cancellationToken = cts.Token) with
| _, FSharpCheckFileAnswer.Aborted -> None
| _, FSharpCheckFileAnswer.Succeeded results -> Some results

Cancellable.HasCancellationToken |> shouldEqual false
result

with :? OperationCanceledException ->
wasCancelled <- true
None
Expand Down

0 comments on commit 1f9b0ce

Please sign in to comment.