Skip to content

Commit

Permalink
Add retries to NoExtraThreadAfterEachChange (#5318)
Browse files Browse the repository at this point in the history
### Description
- Add retries to NoExtraThreadAfterEachChange to make it stable

### How has this been tested?
- PR changes tests

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
  • Loading branch information
keyboardDrummer committed Apr 12, 2024
1 parent 4e586b5 commit 13e39d8
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Source/DafnyLanguageServer.Test/Performance/ThreadUsageTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;

namespace Microsoft.Dafny.LanguageServer.IntegrationTest.Performance;
Expand All @@ -15,16 +16,29 @@ public class ThreadUsageTest : ClientBasedLanguageServerTest {

[Fact]
public async Task NoExtraThreadAfterEachChange() {
var source = "method Foo() { assert false; }";
var document = await CreateOpenAndWaitForResolve(source);
var threadCountBefore = Process.GetCurrentProcess().Threads.Count;
for (var i = 0; i < 10; i++) {
ApplyChange(ref document, new Range(0, 0, 0, 0), "//comment" + Environment.NewLine);
await GetLastDiagnostics(document);
Exception lastException = null;
for (var attempt = 0; attempt < 100; attempt++) {
try {
var source = "method Foo() { assert false; }";
var document = await CreateOpenAndWaitForResolve(source);
var threadCountBefore = Process.GetCurrentProcess().Threads.Count;
for (var i = 0; i < 10; i++) {
ApplyChange(ref document, new Range(0, 0, 0, 0), "//comment" + Environment.NewLine);
await GetLastDiagnostics(document);
}

var threadCountAfter = Process.GetCurrentProcess().Threads.Count;
const int maxThreadCountIncrease = 5;
Assert.InRange(threadCountAfter - threadCountBefore, -maxThreadCountIncrease, maxThreadCountIncrease);
break;
} catch (InRangeException e) {
lastException = e;
}
}

if (lastException != null) {
throw lastException;
}
var threadCountAfter = Process.GetCurrentProcess().Threads.Count;
const int maxThreadCountIncrease = 5;
Assert.InRange(threadCountAfter - threadCountBefore, -maxThreadCountIncrease, maxThreadCountIncrease);
}

public ThreadUsageTest(ITestOutputHelper output, LogLevel dafnyLogLevel = LogLevel.Information)
Expand Down

0 comments on commit 13e39d8

Please sign in to comment.