-
Notifications
You must be signed in to change notification settings - Fork 29
Adds Oracle and Firebird containers with associated tests #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PhenX
wants to merge
3
commits into
Deffiss:master
Choose a base branch
from
PhenX:new-containers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/TestEnvironment.Docker.Containers.Firebird/DockerEnvironmentBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace TestEnvironment.Docker.Containers.Firebird | ||
| { | ||
| public static class DockerEnvironmentBuilderExtensions | ||
| { | ||
| public static IDockerEnvironmentBuilder AddFirebirdContainer( | ||
| this IDockerEnvironmentBuilder builder, | ||
| string name, | ||
| string userName = "user1", | ||
| string password = "p4ssw0rd", | ||
| string imageName = "jacobalberty/firebird", | ||
| string tag = "latest", | ||
| IDictionary<string, string> environmentVariables = null, | ||
| IDictionary<ushort, ushort> ports = null, | ||
| bool reuseContainer = false) | ||
| { | ||
| return builder.AddDependency( | ||
| new FirebirdContainer( | ||
| builder.DockerClient, | ||
| name.GetContainerName(builder.EnvironmentName), | ||
| userName, | ||
| password, | ||
| imageName, | ||
| tag, | ||
| new Dictionary<string, string> | ||
| { | ||
| ["FIREBIRD_USER"] = userName, | ||
| ["FIREBIRD_PASSWORD"] = password, | ||
| ["FIREBIRD_DATABASE"] = "SampleDatabase", | ||
| ["EnableWireCrypt"] = "true", | ||
| ["ISC_PASSWORD"] = password, | ||
| }.MergeDictionaries(environmentVariables), | ||
| ports, | ||
| builder.IsDockerInDocker, | ||
| reuseContainer, | ||
| new FirebirdContainerWaiter(builder.Logger), | ||
| new FirebirdContainerCleaner(builder.Logger, userName), | ||
| builder.Logger)); | ||
| } | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/TestEnvironment.Docker.Containers.Firebird/FirebirdContainer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| using System.Collections.Generic; | ||
| using Docker.DotNet; | ||
| using Microsoft.Extensions.Logging; | ||
| using IP = System.Net.IPAddress; | ||
|
|
||
| namespace TestEnvironment.Docker.Containers.Firebird | ||
| { | ||
| public class FirebirdContainer : Container | ||
| { | ||
| private readonly string _userName; | ||
| private readonly string _password; | ||
|
|
||
| public FirebirdContainer( | ||
| DockerClient dockerClient, | ||
| string name, | ||
| string userName, | ||
| string password, | ||
| string imageName = "jacobalberty/firebird", | ||
| string tag = "latest", | ||
| IDictionary<string, string> environmentVariables = null, | ||
| IDictionary<ushort, ushort> ports = null, | ||
| bool isDockerInDocker = false, | ||
| bool reuseContainer = false, | ||
| IContainerWaiter containerWaiter = null, | ||
| IContainerCleaner containerCleaner = null, | ||
| ILogger logger = null) | ||
| : base( | ||
| dockerClient, | ||
| name, | ||
| imageName, | ||
| tag, | ||
| environmentVariables, | ||
| ports, | ||
| isDockerInDocker, | ||
| reuseContainer, | ||
| containerWaiter, | ||
| containerCleaner, | ||
| logger) | ||
| { | ||
| _userName = userName; | ||
| _password = password; | ||
| } | ||
|
|
||
| public string GetConnectionString() | ||
| { | ||
| var host = IsDockerInDocker ? IPAddress : IP.Loopback.ToString(); | ||
| var port = IsDockerInDocker ? 3050 : Ports[3050]; | ||
| return $"DataSource={host};Port={port};User={_userName};Password={_password};Pooling=false;Database=SampleDatabase"; | ||
| } | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
src/TestEnvironment.Docker.Containers.Firebird/FirebirdContainerCleaner.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using FirebirdSql.Data.FirebirdClient; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace TestEnvironment.Docker.Containers.Firebird | ||
| { | ||
| public class FirebirdContainerCleaner : IContainerCleaner<FirebirdContainer> | ||
| { | ||
| private readonly ILogger _logger; | ||
| private readonly string _userName; | ||
|
|
||
| public FirebirdContainerCleaner(ILogger logger, string userName) | ||
| { | ||
| _logger = logger; | ||
| _userName = userName; | ||
| } | ||
|
|
||
| public async Task Cleanup(FirebirdContainer container, CancellationToken token = default) | ||
| { | ||
| if (container == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(container)); | ||
| } | ||
|
|
||
| var cleanUpQuery = $"DROP OWNED BY {_userName}"; | ||
|
|
||
| using (var connection = new FbConnection(container.GetConnectionString())) | ||
| using (var cleanUpCommand = new FbCommand(cleanUpQuery, connection)) | ||
| { | ||
| try | ||
| { | ||
| await connection.OpenAsync(token); | ||
| await cleanUpCommand.ExecuteNonQueryAsync(token); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger?.LogError($"Firebird cleanup issue: {ex.Message}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public Task Cleanup(Container container, CancellationToken token = default) => Cleanup((FirebirdContainer)container, token); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/TestEnvironment.Docker.Containers.Firebird/FirebirdContainerWaiter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using FirebirdSql.Data.FirebirdClient; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace TestEnvironment.Docker.Containers.Firebird | ||
| { | ||
| public class FirebirdContainerWaiter : BaseContainerWaiter<FirebirdContainer> | ||
| { | ||
| public FirebirdContainerWaiter(ILogger logger) | ||
| : base(logger) | ||
| { | ||
| } | ||
|
|
||
| protected override async Task<bool> PerformCheck(FirebirdContainer container, CancellationToken cancellationToken) | ||
| { | ||
| using var connection = new FbConnection(container.GetConnectionString()); | ||
| using var command = new FbCommand("SELECT rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database;", connection); | ||
|
|
||
| await connection.OpenAsync(cancellationToken); | ||
| await command.ExecuteNonQueryAsync(cancellationToken); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
...tEnvironment.Docker.Containers.Firebird/TestEnvironment.Docker.Containers.Firebird.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <AssemblyName>TestEnvironment.Docker.Containers.Firebird</AssemblyName> | ||
| <RootNamespace>TestEnvironment.Docker.Containers.Firebird</RootNamespace> | ||
| <Version>1.0.7</Version> | ||
| <PackageId>TestEnvironment.Docker.Containers.Firebird</PackageId> | ||
| <Authors>Fabien Ménager</Authors> | ||
| <Description>Add Firebird container specific functionality.</Description> | ||
| <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
| <PackageTags>docker tests firebird container</PackageTags> | ||
| <PackageReleaseNotes>Update to the latest nugets.</PackageReleaseNotes> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\TestEnvironment.Docker\TestEnvironment.Docker.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="7.5.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
37 changes: 37 additions & 0 deletions
37
src/TestEnvironment.Docker.Containers.Oracle/DockerEnvironmentBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace TestEnvironment.Docker.Containers.Oracle | ||
| { | ||
| public static class DockerEnvironmentBuilderExtensions | ||
| { | ||
| public static IDockerEnvironmentBuilder AddOracleContainer( | ||
| this IDockerEnvironmentBuilder builder, | ||
| string name, | ||
| string userName = "system", | ||
| string password = "oracle", | ||
| string imageName = "wnameless/oracle-xe-11g-r2", | ||
| string tag = "latest", | ||
| IDictionary<string, string> environmentVariables = null, | ||
| IDictionary<ushort, ushort> ports = null, | ||
| bool reuseContainer = false) | ||
| { | ||
| return builder.AddDependency( | ||
| new OracleContainer( | ||
| builder.DockerClient, | ||
| name.GetContainerName(builder.EnvironmentName), | ||
| userName, | ||
| password, | ||
| imageName, | ||
| tag, | ||
| new Dictionary<string, string> | ||
| { | ||
| }.MergeDictionaries(environmentVariables), | ||
| ports, | ||
| builder.IsDockerInDocker, | ||
| reuseContainer, | ||
| new OracleContainerWaiter(builder.Logger), | ||
| new OracleContainerCleaner(builder.Logger, userName), | ||
| builder.Logger)); | ||
| } | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/TestEnvironment.Docker.Containers.Oracle/OracleContainer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| using System.Collections.Generic; | ||
| using Docker.DotNet; | ||
| using Microsoft.Extensions.Logging; | ||
| using IP = System.Net.IPAddress; | ||
|
|
||
| namespace TestEnvironment.Docker.Containers.Oracle | ||
| { | ||
| public class OracleContainer : Container | ||
| { | ||
| private readonly string _userName; | ||
| private readonly string _password; | ||
|
|
||
| public OracleContainer( | ||
| DockerClient dockerClient, | ||
| string name, | ||
| string userName, | ||
| string password, | ||
| string imageName = "wnameless/oracle-xe-11g-r2", | ||
| string tag = "latest", | ||
| IDictionary<string, string> environmentVariables = null, | ||
| IDictionary<ushort, ushort> ports = null, | ||
| bool isDockerInDocker = false, | ||
| bool reuseContainer = false, | ||
| IContainerWaiter containerWaiter = null, | ||
| IContainerCleaner containerCleaner = null, | ||
| ILogger logger = null) | ||
| : base( | ||
| dockerClient, | ||
| name, | ||
| imageName, | ||
| tag, | ||
| environmentVariables, | ||
| ports, | ||
| isDockerInDocker, | ||
| reuseContainer, | ||
| containerWaiter, | ||
| containerCleaner, | ||
| logger) | ||
| { | ||
| _userName = userName; | ||
| _password = password; | ||
| } | ||
|
|
||
| public string GetConnectionString() | ||
| { | ||
| var host = IsDockerInDocker ? IPAddress : IP.Loopback.ToString(); | ||
| var port = IsDockerInDocker ? 1521 : Ports[1521]; | ||
| return $"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={host})(PORT={port})))(CONNECT_DATA=(SERVICE_NAME=XE)));User ID={_userName};Password={_password}"; | ||
| } | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
src/TestEnvironment.Docker.Containers.Oracle/OracleContainerCleaner.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.Logging; | ||
| using Oracle.ManagedDataAccess.Client; | ||
|
|
||
| namespace TestEnvironment.Docker.Containers.Oracle | ||
| { | ||
| public class OracleContainerCleaner : IContainerCleaner<OracleContainer> | ||
| { | ||
| private readonly ILogger _logger; | ||
| private readonly string _userName; | ||
|
|
||
| public OracleContainerCleaner(ILogger logger, string userName) | ||
| { | ||
| _logger = logger; | ||
| _userName = userName; | ||
| } | ||
|
|
||
| public async Task Cleanup(OracleContainer container, CancellationToken token = default) | ||
| { | ||
| if (container == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(container)); | ||
| } | ||
|
|
||
| var cleanUpQuery = $"DROP OWNED BY {_userName}"; | ||
|
|
||
| using (var connection = new OracleConnection(container.GetConnectionString())) | ||
| using (var cleanUpCommand = new OracleCommand(cleanUpQuery, connection)) | ||
| { | ||
| try | ||
| { | ||
| await connection.OpenAsync(token); | ||
| await cleanUpCommand.ExecuteNonQueryAsync(token); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger?.LogError($"Oracle cleanup issue: {ex.Message}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public Task Cleanup(Container container, CancellationToken token = default) => Cleanup((OracleContainer)container, token); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/TestEnvironment.Docker.Containers.Oracle/OracleContainerWaiter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.Logging; | ||
| using Oracle.ManagedDataAccess.Client; | ||
|
|
||
| namespace TestEnvironment.Docker.Containers.Oracle | ||
| { | ||
| public class OracleContainerWaiter : BaseContainerWaiter<OracleContainer> | ||
| { | ||
| public OracleContainerWaiter(ILogger logger) | ||
| : base(logger) | ||
| { | ||
| } | ||
|
|
||
| protected override async Task<bool> PerformCheck(OracleContainer container, CancellationToken cancellationToken) | ||
| { | ||
| using var connection = new OracleConnection(container.GetConnectionString()); | ||
| using var command = new OracleCommand("SELECT * FROM V$VERSION", connection); | ||
|
|
||
| await connection.OpenAsync(cancellationToken); | ||
|
|
||
| var info = connection.GetSessionInfo(); | ||
| info.TimeZone = "UTC"; | ||
| connection.SetSessionInfo(info); | ||
|
|
||
| await command.ExecuteNonQueryAsync(cancellationToken); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing with error:
Probably you need to specify additional parameters to default connection string or configure IsRetryable property in the similar way as in https://github.com/Deffiss/testenvironment-docker/blob/master/src/TestEnvironment.Docker.Containers.MariaDB/MariaDBContainerWaiter.cs#L29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, this is how timezome might be set on connection level
https://stackoverflow.com/questions/53510011/asp-net-core-docker-container-using-oracle-managed-driver-core-throws-ora-00604
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I tried to add the timezone in the env vars, let's see if that's enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the AppVeyoir build timed out :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still
ORA-01882: timezone region not founderrors in appveyor, I suspect there is noUTCtimezone inside Docker image. I'll try to troubleshoot locally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still no luck ... Maybe with a more "common" timezone like "Europe/Paris" ? I checked, UTC exists in the Oracle timezone table though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, very strange. Locally it works just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some research and found that in
HealthCheckproject Oracle tests are skipped for some reasons on AppVeyor:https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/test/FunctionalTests/HealthChecks.Oracle/OracleHealthCheckTests.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My current feeling that in AppVeyor there is a discrepancy between timezones inside container and on builder machine, we need to find a way to identify timezone that exists in two places.