Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

error TESTERROR: GetDownload (53ms): Error Message: Error calling Test Cleanup method for test class Aiursoft.Tracer.Tests.IntegrationTests.BasicTests: System.MethodAccessException: Attempt by method #5072

Closed
Anduin2017 opened this issue Feb 19, 2025 · 2 comments
Assignees

Comments

@Anduin2017
Copy link
Member

After upgrading:

Exit code is 0

Last runner error: Process /usr/lib/dotnet/dotnet:192904 exited with code '0'.

--- EXCEPTION #1/1 [LoggerException]
Message = “Process /usr/lib/dotnet/dotnet:192904 exited with code '0'.”
StackTraceString = “
  at JetBrains.Util.ILoggerEx.LogMessage(ILogger logger, LoggingLevel level, String message) in LogMessage.il:line IL_002E mvid 48B4
     at JetBrains.Util.ILoggerEx.Error(ILogger logger, String message) in Error.il:line IL_0000 mvid 48B4
     at JetBrains.ReSharper.UnitTestFramework.Execution.TestRunner.TestRunnerRunStrategy.AnalyseProcessCrash(ProcessExitedUnexpectedlyException ex, IUnitTestRun run) in AnalyseProcessCrash.il:line IL_006B mvid 1598
     at JetBrains.ReSharper.UnitTestFramework.Execution.TestRunner.TestRunnerRunStrategy.Run(IUnitTestRun run) in Run.il:line IL_01C8 mvid 1598
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid C608
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext() in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in RunOrScheduleAction.il:line IL_003B mvid C608
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid C608 or RunContinuations.il:line IL_0090 mvid C608
     at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute) in FinishSlow.il:line IL_0003 mvid C608
     at System.Threading.Tasks.Task.TrySetException(Object exceptionObject) in TrySetException.il:line IL_0022 mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.SetException(Exception exception, Task1& taskField) in SetException.il:line IL_0025 mvid C608
     at JetBrains.ReSharper.UnitTestFramework.Execution.TestRunner.TestRunnerAgentManager.TestRunnerExecutionAgent.RunTests(CancellationToken cancelCt, CancellationToken abortCt) in RunTests.il:line IL_00AE mvid 1598
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid C608
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext() in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in RunOrScheduleAction.il:line IL_003B mvid C608
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid C608 or RunContinuations.il:line IL_0090 mvid C608
     at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute) in FinishSlow.il:line IL_0003 mvid C608
     at System.Threading.Tasks.Task.TrySetException(Object exceptionObject) in TrySetException.il:line IL_0022 mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.SetException(Exception exception, Task1& taskField) in SetException.il:line IL_0025 mvid C608
     at JetBrains.ReSharper.UnitTestFramework.Common.Extensions.TaskExtensions.CancelIf(Task task, CancellationToken ct, TaskCreationOptions options) in CancelIf.il:line IL_0126 mvid 1598
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid C608
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext() in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in RunOrScheduleAction.il:line IL_003B mvid C608
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid C608 or RunContinuations.il:line IL_0090 mvid C608
     at System.Threading.Tasks.Task1.TrySetResult(TResult result) in TrySetResult.il:line IL_004B mvid C608
     at System.Threading.Tasks.Task.TwoTaskWhenAnyPromise1.Invoke(Task completingTask) in Invoke.il:line IL_0088 mvid C608
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid C608 or RunContinuations.il:line IL_0090 mvid C608
     at System.Threading.Tasks.Task.FinishSlow(Boolean userDelegateExecute) in FinishSlow.il:line IL_0003 mvid C608
     at System.Threading.Tasks.Task.TrySetException(Object exceptionObject) in TrySetException.il:line IL_0022 mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.SetException(Exception exception, Task1& taskField) in SetException.il:line IL_0025 mvid C608
     at JetBrains.ReSharper.UnitTestFramework.Common.Extensions.TaskExtensions.ThrowIf[TException](Task task, Task signallingTask, Func1 exceptionFactory) in ThrowIf.il:line IL_00A9 mvid 1598
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid C608
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in RunInternal.il:line IL_0040 mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext() in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining) in RunOrScheduleAction.il:line IL_003B mvid C608
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid C608 or RunContinuations.il:line IL_0090 mvid C608
     at System.Threading.Tasks.Task1.TrySetResult(TResult result) in TrySetResult.il:line IL_004B mvid C608
     at System.Threading.Tasks.Task.TwoTaskWhenAnyPromise1.Invoke(Task completingTask) in Invoke.il:line IL_0088 mvid C608
     at System.Threading.Tasks.Task.RunContinuations(Object continuationObject) in RunContinuations.il:line IL_0065 mvid C608 or RunContinuations.il:line IL_0090 mvid C608
     at JetBrains.Util.ProcessExtensions.WaitForExitAsync(IPreparedProcess process, CancellationToken token) in WaitForExitAsync.il:line IL_018C mvid 3FCB
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.ExecutionContextCallback(Object s) in ExecutionContextCallback.il:line IL_0000 mvid C608
     at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) in RunFromThreadPoolDispatchLoop.il:line IL_0015 mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) in MoveNext.il:line IL_0000 mvid C608 or MoveNext.il:line IL_0040 mvid C608 or MoveNext.il:line IL_004E mvid C608
     at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.ExecuteFromThreadPool(Thread threadPoolThread) in ExecuteFromThreadPool.il:line IL_0000 mvid C608
     at System.Threading.ThreadPoolWorkQueue.Dispatch() in Dispatch.il:line IL_013F mvid C608
     at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in WorkerThreadStart.il:line IL_00A0 mvid C608
”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
HResult = COR_E_APPLICATION=80131600

I also tried calling from dotnet test:

 /usr/lib/dotnet/sdk/9.0.102/Microsoft.TestPlatform.targets(48,5): error TESTERROR: 
      GetDownload (53ms): Error Message: Error calling Test Cleanup method for test class Aiursoft.Tracer.Tests.IntegrationTests.BasicTests: System.MethodAccessException: Attempt by method 'Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodInfo.RunTestCleanupMethod(Microsoft.VisualS
      tudio.TestTools.UnitTesting.TestResult, System.Threading.CancellationTokenSource)' to access method 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.set_CancellationTokenSource(System.Threading.CancellationTokenSource)' failed.

However, 3.7.3 doesn't have this issue.

My test code:

using Aiursoft.CSTools.Tools;
using AngleSharp.Html.Dom;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Aiursoft.Tracer.Tests.Tools;
using Microsoft.Extensions.Hosting;
using static Aiursoft.WebTools.Extends;
using Aiursoft.AiurObserver.DefaultConsumers;
using Aiursoft.AiurObserver.WebSocket;

namespace Aiursoft.Tracer.Tests.IntegrationTests;

[TestClass]
public class BasicTests
{
    private readonly string _endpointUrl;
    private readonly int _port;
    private readonly HttpClient _http;
    private IHost? _server;

    public BasicTests()
    {
        _port = Network.GetAvailablePort();
        _endpointUrl = $"http://localhost:{_port}";
        _http = new HttpClient();
    }

    [TestInitialize]
    public async Task CreateServer()
    {
        _server = await AppAsync<Startup>([], port: _port);
        await _server.StartAsync();
    }

    [TestCleanup]
    public async Task CleanServer()
    {
        if (_server == null) return;
        await _server.StopAsync();
        _server.Dispose();
    }

    [TestMethod]
    public async Task GetHome()
    {
        var response = await _http.GetAsync(_endpointUrl);
        var doc = await HtmlHelpers.GetDocumentAsync(response);

        response.EnsureSuccessStatusCode(); // Status Code 200-299
        Assert.AreEqual("text/html; charset=utf-8", response.Content.Headers.ContentType?.ToString());
        var p = doc.QuerySelector("p.lead") as IHtmlElement;
        Assert.AreEqual(
            "Aiursoft Tracer is a simple network quality testing app. Helps testing the connection speed between you and the server.",
            p?.InnerHtml);
    }

    [TestMethod]
    public async Task GetDownload()
    {
        var url = _endpointUrl + "/download.dat";
        var response = await _http.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
        response.EnsureSuccessStatusCode(); // Status Code 200-299
    }

    [TestMethod]
    public async Task Ping()
    {
        var url = _endpointUrl + "/pINg";
        var response = await _http.GetAsync(url);
        var content = await response.Content.ReadAsStringAsync();

        response.EnsureSuccessStatusCode(); // Status Code 200-299
        Assert.AreEqual("application/json; charset=utf-8", response.Content.Headers.ContentType?.ToString());
        Assert.AreEqual("[]", content);
    }

    [TestMethod]
    public async Task TestConnect()
    {
        var endPoint = _endpointUrl.Replace("http", "ws") + "/Home/Pushing";
        var socket = await endPoint.ConnectAsWebSocketServer();
        await Task.Factory.StartNew(() => socket.Listen());

        var counter = new MessageCounter<string>();
        socket.Subscribe(counter);
        var lastStage = new MessageStageLast<string>(); 
        socket.Subscribe(lastStage);
        await Task.Delay(5000);
        await socket.Close();
        await Task.Delay(10);

        var latestTime = lastStage.Stage?.Split('|')[0];
        Assert.IsTrue(DateTime.TryParse(latestTime, out _), $"Got message {latestTime} is not a date time.");
        Assert.IsTrue(counter.Count > 30);
        Assert.IsTrue(counter.Count < 70);
    }
}

My csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <RootNamespace>Aiursoft.Tracer.Tests</RootNamespace>
    <IsTestProject>true</IsTestProject>
    <IsPackable>false</IsPackable>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Aiursoft.AiurObserver.Extensions" Version="9.0.0" />
    <PackageReference Include="coverlet.collector" Version="6.0.4">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="JunitXml.TestLogger" Version="5.0.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
    <PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
    <PackageReference Include="AngleSharp" Version="1.2.0" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\src\Aiursoft.Tracer\Aiursoft.Tracer.csproj" />
  </ItemGroup>
</Project>

Project clone endpoint: https://gitlab.aiursoft.cn/aiursoft/tracer.git

@Youssef1313
Copy link
Member

Youssef1313 commented Feb 19, 2025

Thanks for reporting this. Just to be sure, did you update both MSTest.TestAdapter and MSTest.TestFramework? If you only update TestAdapter, then it's expected to not work.

@Youssef1313
Copy link
Member

I investigated this issue, and it seems that in your repo there is a net9.0 directory besides the csproj which is containing 3.7.3 binaries and it is causing issues. If you delete this directory, it should work correctly.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants