I am trying to create integration tests for my microservices similar to Spotify's approach.
I am still working on how to spin up and seed the database. Currently I have a .NET Core 2.0 project with FluentDocker v2.2.15 and DbUp 4.1.0.
I use FluentDocker to call DockerCompose and start my services, including the SQL Server container
var hosts = new Hosts().Discover();
var dockerHost = hosts.FirstOrDefault(x => x.IsNative) ?? hosts.FirstOrDefault(x => x.Name == "default");
if (dockerHost == null)
{
return;
}
var composeFile = Args["composeFile"];
var result = dockerHost.Host.ComposeUp(composeFile: composeFile);
and then I use DbUp to run my scripts and seed the database.
var connectionString = Args["connectionString"];
var scriptsPath = Args["scriptsPath"];
EnsureDatabase.For.SqlDatabase(connectionString);
var upgradeEngine = DeployChanges.To.SqlDatabase(connectionString).WithScriptsFromFileSystem(scriptsPath).Build();
var result = upgradeEngine.PerformUpgrade();
I can run this successfully when I give SQL Server enough time to start, for example, when debugging. However, if I run this at full speed, then DbUp tries to connect to SQL Server when it isn't ready yet.
FluentDocker has a WaitForPort
method but it doesn't seem to work with DockerCompose API.
I would like to know if there is a way to wait for SQL Server's port 1433 to be responsive before running the scripts (excluding non-deterministic tactics such as await Task.Delay
) or if there are alternative libraries that allow me to have this kind of control.
Thanks