2

I have a XUnit project, that when starting up initializes a server in the class constructor:

public OPCUASampleServerTest(OPCTagList oPCTagList)
{
    MySampleServer server = new(true, 3600, null);
    this.thread = new Thread(() => server.Run());
    this.thread.Start();
    this._taglist = oPCTagList.Taglist;
}

The tests utilizing the server, communicates to it via localhost and all works fine on my machine. I have also tested it by cloning the code to assure that everything is present in the repository. Everything compiles as expected. I am trying to have the same result on an Azure pipeline. I have a working pipeline that builds and runs the initial test cases, WITHOUT the server. Now after adding this OPCUASampleServerTest the test fails on the server, but not on my machine. The error is that it is not able to connect to the server

OPCUAClass opc = new("localhost", "51210", this._taglist, 300, false);
bool connected = opc.InitializeOPCUAClient(); //returns false on server, and true on running it on my own machine

I am therefore thinking that the issue is that it cannot see/connect to localhost. Is there some specific setting I am missing in my test function in the pipeline that looks like this:

- task: DotNetCoreCLI@2
  displayName: Test xUnit
  inputs:
    command: test
    projects: '**/OPCDLL.Test.csproj'
    arguments: '--configuration $(buildConfiguration) --collect "Code coverage" --no-build'
    testRunTitle: 'Generic Repository Tests'
    publishTestResults: true

Running what I interpret as the same function using the dotnet CLI:

dotnet test OPCDLL.Test.csproj  --configuration Release --collect "Code coverage" --no-build --framework net5.0

I get 4 passed tests, as it should be. So there is definitely something spurious in the azure run?

JTIM
  • 2,774
  • 1
  • 34
  • 74
  • Check https://stackoverflow.com/questions/64502381/azure-devops-pipeline-tests-that-pass-locally-fail-on-the-pipeline. – Mr Qian May 27 '21 at 09:54
  • @PerryQian-MSFT so your saying it is a timing issue? Any method for me to debug this? I am not specifically relying on timings, but I guess it is happening in the tcp.opc communication protocol implemented by OPC foundation. Still shouldn't a test that is running fine in VS and via commandline be able to run on the Azure Pipeline? – JTIM May 27 '21 at 11:46
  • @PerryQian-MSFT if you refer to the tool they reference `Visual Studio Test Platform Installer` I cannot find this in the available tasks on the pipeline – JTIM May 27 '21 at 11:50
  • @PerryQian-MSFT `- task: VSTest@2 inputs: testSelector: 'testAssemblies' testAssemblyVer2: | **/OPCDLL.Test.csproj !**\*TestAdapter.dll !**\obj\** searchFolder: '$(System.DefaultWorkingDirectory)' codeCoverageEnabled: true runInParallel: false runTestsInIsolation: true diagnosticsEnabled: true rerunFailedTests: true rerunMaxAttempts: 3` I tried with VSTest, but it does not find the tests, I guess that .NET5.0 is not supported? – JTIM May 27 '21 at 12:14
  • Are you raising 1 server per test? – Juanma Feliu Jun 04 '21 at 08:16
  • No only this one extra test – JTIM Jun 05 '21 at 06:04
  • Can you add some info about the library you use to raise this server? Have you tried using OWIN? are you using hosted agents or self-hosted with a VM? Maybe you are missing some installation in your build machine if you are using self-hosted agents. – Juanma Feliu Jun 06 '21 at 07:37

0 Answers0