Running server and dependent unit tests connection issues

77 views Asked by At

I am trying to run some xunit tests which require a server that is running. I have seen some posts similar to this. I am trying something like in here, but can't get it to work.

I also went to the "Advance Settings" under "Firewall and Network Security" and added port 3333 to allow connection for the inbound and out bound ports. No matter what, when I run the unit tests after running the server, I get error saying.

Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333.

The action goes into an endless loop after the error until I cancel the workflow.

Here is my entire workflow file. But please see the last step to run the CoreServer.exe in background and run the FluidtransferTests.

name: Test unit tests CI

on:
  push:
    branches: [ "dev" ]
  pull_request:
    branches: [ "dev" ]

  
jobs:
  build:

    runs-on: windows-2022

    steps:
    - uses: actions/checkout@v3

    - name: setup Msbuild
      uses: microsoft/[email protected]

    - name: Setup NuGet
      uses: NuGet/[email protected]

    - name: Setup VSTest Console
      uses: darenm/[email protected]


#Restore NuGet packages for CoreServer and build the Solution.

    - name: Restore NuGet packages for CoreServer
      run: nuget restore ./Core/CoreServer/CoreServer.sln

    - name: Build the CoreServer solution
      run: msbuild ./Core/CoreServer/CoreServer.sln /p:platform="Any CPU" /p:configuration="Release"
      

#Restore NuGet packages for CoreClient and build the Solution.

    - name: Restore NuGet packages for CoreClient
      run: nuget restore ./Core/CoreServer/CoreClient.sln

    - name: Build the CoreClient solution
      run: msbuild ./Core/CoreServer/CoreClient.sln /p:platform="Any CPU" /p:configuration="Release"


#Restore NuGet packages for EchoNETServer and build the Solution.

    - name: Restore NuGet packages for EchoNETServer
      run: nuget restore ./EchoNET/EchoNETServer.sln

    - name: Build the EchoNETServer solution
      run: msbuild ./EchoNET/EchoNETServer.sln /p:platform="Any CPU" /p:configuration="Release"


#Restore NuGet packages for EchoNETClient and build the Solution.
    
    - name: Restore NuGet packages for EchoNETClient
      run: nuget restore ./EchoNET/EchoNETClient.sln

    - name: Build the EchoNETClient solution
      run: msbuild ./EchoNET/EchoNETClient.sln /p:platform="Any CPU" /p:configuration="Release"


#Restore NuGet packages for EchoServer and build the Solution.
    
    - name: Restore NuGet packages for EchoServer
      run: nuget restore ./Echo/EchoServer.sln

    - name: Build the EchoServer solution
      run: msbuild ./Echo/EchoServer.sln /p:platform="Any CPU" /p:configuration="Release"

#Wait for the actions to complete before startinhg

    - name: Delay for the process to complete
      run: sleep 7
      

#Start CoreServer.exe in background and run the FluidtransferTests
    
    - name: Start CoreServer.exe in the background and run the FluidTransferTests
      run: |
         ./Core/CoreServer/Server/CoreServer/Bin/Debug/CoreServer.exe -c -s &
         vstest.console.exe ./Pico/Medman/FluidTransferTests/bin/Release/net481/FluidTransferTests.dll

Upon running this, it shows the following output.

Run ./Core/CoreServer/Server/CoreServer/Bin/Debug/CoreServer.exe -c -s &

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      Job1            BackgroundJob   Running       True            localhost            Microsoft.PowerShell.Man…
Microsoft (R) Test Execution Command Line Tool Version 17.7.2 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.5+1caef2f33e (64-bit Desktop .NET 4.0.30319.42000)
[xUnit.net 00:00:01.49]   Discovering: FluidTransferTests
[xUnit.net 00:00:02.42]   Discovered:  FluidTransferTests
[xUnit.net 00:00:02.45]   Starting:    FluidTransferTests
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect to command client exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Connect Exception: No connection could be made because the target machine actively refused it 127.0.0.1:3333
Error: The operation was canceled.

EDIT:

So in the run step, I tried something like this,

 - name: Start CoreServer.exe in the background and run the FluidTransferTests
      run: |
         ./Core/CoreServer/Server/CoreServer/Bin/Debug/CoreServer.exe -c -s &
         curl http://localhost:3333 -I
         vstest.console.exe ./Pico/Medman/FluidTransferTests/bin/Release/net481/FluidTransferTests.dll

Upon running this, I get curl: (7) Failed to connect to localhost port 3333 after 2225 ms: Couldn't connect to server

When I run the CoreServer and the netstat -a on my local it says it is listening on ports 3333. Please see this screenshot.

ports used

0

There are 0 answers