Skip to content

Commit

Permalink
Fix the Redis test bugs in integration tests (Azure#1957)
Browse files Browse the repository at this point in the history
* Wait until redis is there

* Adapt to comments

* Remove the former notice imports

* Fix mixup between PRs
  • Loading branch information
Mandur authored and ouphi committed Nov 2, 2022
1 parent 86e2316 commit 0c11b7f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
# Pull Redis Cache docker image
- name: Pulling Redis Cache image
run: docker pull redis:5.0.4-alpine
run: docker pull redis:6.0-alpine

# Run integration tests
- name: Run integration tests
Expand Down
5 changes: 3 additions & 2 deletions LoRaEngine/modules/LoRaWanNetworkSrvModule/Dockerfile.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ COPY Directory.Build.props ./
COPY AssemblyInfo.cs ./
COPY .editorconfig ./
COPY global.json ./
COPY LICENSE ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/NOTICE.txt ./

WORKDIR /build/LoRaEngine/modules
COPY ["LoRaEngine/modules/LoRaWan.NetworkServerDiscovery/LoRaWan.NetworkServerDiscovery.csproj", "LoRaWan.NetworkServerDiscovery/"]
Expand Down Expand Up @@ -34,5 +32,8 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim
WORKDIR /app
COPY --from=build-env /build/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWanNetworkSrvModule/out/* ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/start.sh ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/NOTICE.txt ./
COPY LICENSE ./

RUN chmod +x ./start.sh
ENTRYPOINT ["./start.sh"]
5 changes: 3 additions & 2 deletions LoRaEngine/modules/LoRaWanNetworkSrvModule/Dockerfile.arm32v7
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ COPY Directory.Build.props ./
COPY AssemblyInfo.cs ./
COPY .editorconfig ./
COPY global.json ./
COPY LICENSE ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/NOTICE.txt ./

WORKDIR /build/LoRaEngine/modules
COPY ["LoRaEngine/modules/LoRaWan.NetworkServerDiscovery/LoRaWan.NetworkServerDiscovery.csproj", "LoRaWan.NetworkServerDiscovery/"]
Expand Down Expand Up @@ -34,5 +32,8 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim-arm32v7
WORKDIR /app
COPY --from=build-env /build/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWanNetworkSrvModule/out/* ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/start.sh ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/NOTICE.txt ./
COPY LICENSE ./

RUN chmod +x ./start.sh
ENTRYPOINT ["./start.sh"]
5 changes: 3 additions & 2 deletions LoRaEngine/modules/LoRaWanNetworkSrvModule/Dockerfile.arm64v8
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ COPY Directory.Build.props ./
COPY AssemblyInfo.cs ./
COPY .editorconfig ./
COPY global.json ./
COPY LICENSE ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/NOTICE.txt ./

WORKDIR /build/LoRaEngine/modules
COPY ["LoRaEngine/modules/LoRaWan.NetworkServerDiscovery/LoRaWan.NetworkServerDiscovery.csproj", "LoRaWan.NetworkServerDiscovery/"]
Expand Down Expand Up @@ -34,5 +32,8 @@ FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim-arm64v8
WORKDIR /app
COPY --from=build-env /build/LoRaEngine/modules/LoRaWanNetworkSrvModule/LoRaWanNetworkSrvModule/out/* ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/start.sh ./
COPY LICENSE ./
COPY ./LoRaEngine/modules/LoRaWanNetworkSrvModule/NOTICE.txt ./

RUN chmod +x ./start.sh
ENTRYPOINT ["./start.sh"]
30 changes: 22 additions & 8 deletions Tests/Integration/RedisFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace LoRaWan.Tests.Integration
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Docker.DotNet;
using Docker.DotNet.Models;
Expand All @@ -23,7 +24,7 @@ public class RedisFixture : IAsyncLifetime
public const string CollectionName = "rediscollection";
private const string ContainerName = "redis";
private const string ImageName = "redis";
private const string ImageTag = "5.0.4-alpine";
private const string ImageTag = "6.0-alpine";
private const int RedisPort = 6001;
private static readonly string TestContainerName = ContainerName + RedisPort;

Expand All @@ -44,7 +45,6 @@ private async Task StartRedisContainer()

try
{

Console.WriteLine("On Premise execution detected");
Console.WriteLine("Starting container...");
containers = await client.Containers.ListContainersAsync(new ContainersListParameters() { All = true });
Expand Down Expand Up @@ -124,17 +124,31 @@ public async Task InitializeAsync()
await StartRedisContainer();

var redisConnectionString = $"localhost:{RedisPort}";
try
var isRedisReady = false;
var maxNumberOfRetries = 5;
var tryRun = 0;
while (!isRedisReady && tryRun < maxNumberOfRetries)
{
this.Redis = await ConnectionMultiplexer.ConnectAsync(redisConnectionString);
Database = this.Redis.GetDatabase();
try
{
Redis = await ConnectionMultiplexer.ConnectAsync(redisConnectionString);
Database = this.Redis.GetDatabase();
isRedisReady = true;
}
catch (RedisConnectionException ex)
{
await Task.Delay(2000);
tryRun++;
Console.WriteLine($"Failed to connect to redis at '{redisConnectionString}'. If running locally with docker: run 'docker run -d -p 6379:6379 redis'. If running in Azure DevOps: run redis in docker.", ex);
}
}
catch (Exception ex)

if (tryRun >= maxNumberOfRetries)
{
throw new InvalidOperationException($"Failed to connect to redis at '{redisConnectionString}'. If running locally with docker: run 'docker run -d -p 6379:6379 redis'. If running in Azure DevOps: run redis in docker.", ex);
throw new InvalidOperationException($"Failed to connect to redis at '{redisConnectionString}'. If running locally with docker: run 'docker run -d -p 6379:6379 redis'. If running in Azure DevOps: run redis in docker.");
}
}


public async Task DisposeAsync()
{
Expand Down

0 comments on commit 0c11b7f

Please sign in to comment.