Integration test is unable to connect to Postgres 9.6 Db in Jenkins

1

Description: A .Net Core 3.1 Web API project contains an IHostedService-implementing service which reads cache data from PostgresDB in StartAsync method. This cache-retrieving service has been registered in Startup's ConfigureServices method

Problem: While running integration tests in Jenkins I've found that exception is being thrown while trying to connect to the Db:

[19:49:34 ERR] An error occurred using the connection to database 'FooDb' on server 'tcp://localhost:5432'.
[19:49:34 INF] A transient exception has been encountered during execution and the operation will be retried after 0ms.
Npgsql.NpgsqlException (0x80004005): Exception while connecting
 ---> System.Net.Sockets.SocketException (99): Cannot assign requested address
   at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state)
   at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state, Boolean flowContext)
   at System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state)
   at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP)
   at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.ConnectorPool.AllocateLong(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()

This issue is limited to integration tests run, e.g. the service works fine in other scenarios.

What have I tried so far?

  1. As per MSDN suggestion I've moved the registration of my cache reading service to Program.cs CreateHostBuilder method;
  2. Refactored cache retrieval to IStartupFilter implementation none of these steps helped.

Also, I've removed the cache reading service's registration to confirm that its invocation is causing the issue. Indeed, everything works fine if I don't add the cache reading service.

jenkins
.net-core
database-connection
postgresql-9.6
asked on Stack Overflow Nov 25, 2020 by makumazan84

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0