Skip to content

Commit d6a0d1f

Browse files
authored
Merge pull request eventflow#758 from FortisOnline/local-integration-tests
Allow to run integration tests locally
2 parents 0d616cf + 01dff96 commit d6a0d1f

6 files changed

Lines changed: 96 additions & 5 deletions

File tree

Source/EventFlow.Elasticsearch.Tests/IntegrationTests/ElasticsearchReadModelStoreTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ public class ElasticsearchReadModelStoreTests : TestSuiteForReadModelStore
5555

5656
protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
5757
{
58-
var elasticsearchUrl = Environment.GetEnvironmentVariable("ELASTICSEARCH_URL");
58+
var elasticsearchUrl = Environment.GetEnvironmentVariable("ELASTICSEARCH_URL") ?? "http://localhost:9200";
59+
60+
// Setup connection settings separateley as by default EventFlow uses SniffingConnectionPool
61+
// which is not working well with elasticserch hosted in local docker
62+
var connectionSettings = new ConnectionSettings(new Uri(elasticsearchUrl))
63+
.ThrowExceptions()
64+
.SniffLifeSpan(TimeSpan.FromMinutes(5))
65+
.DisablePing();
5966

6067
var resolver = eventFlowOptions
6168
.RegisterServices(sr => { sr.RegisterType(typeof(ThingyMessageLocator)); })
62-
.ConfigureElasticsearch(elasticsearchUrl)
69+
.ConfigureElasticsearch(connectionSettings)
6370
.UseElasticsearchReadModelFor<ThingyAggregate, ThingyId, ElasticsearchThingyReadModel>()
6471
.UseElasticsearchReadModel<ElasticsearchThingyMessageReadModel, ThingyMessageLocator>()
6572
.AddQueryHandlers(

Source/EventFlow.EventStores.EventStore.Tests/IntegrationTests/EventStoreEventStoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class EventStoreEventStoreTests : TestSuiteForEventStore
4242
{
4343
protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
4444
{
45-
var eventStoreUri = new Uri(Environment.GetEnvironmentVariable("EVENTSTORE_URL"));
45+
var eventStoreUri = new Uri(Environment.GetEnvironmentVariable("EVENTSTORE_URL") ?? "tcp://admin:changeit@localhost:1113");
4646

4747
var connectionSettings = ConnectionSettings.Create()
4848
.EnableVerboseLogging()

Source/EventFlow.PostgreSql.Tests/TestHelpers/PostgresSqlHelpz.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static PostgreSqlConnectionString CreateConnectionString(string label)
5151

5252
var environmentServer = Environment.GetEnvironmentVariable("HELPZ_POSTGRESQL_SERVER", EnvironmentVariableTarget.Machine);
5353
var environmentPort = Environment.GetEnvironmentVariable("HELPZ_POSTGRESQL_PORT", EnvironmentVariableTarget.Machine);
54-
var environmentPassword = Environment.GetEnvironmentVariable("HELPZ_POSTGRESQL_PASS");
54+
var environmentPassword = Environment.GetEnvironmentVariable("HELPZ_POSTGRESQL_PASS") ?? "Password12!";
5555
var envrionmentUsername = Environment.GetEnvironmentVariable("HELPZ_POSTGRESQL_USER", EnvironmentVariableTarget.Machine);
5656

5757

Source/EventFlow.TestHelpers/MsSql/MsSqlHelpz.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ namespace EventFlow.TestHelpers.MsSql
2929
{
3030
public static class MsSqlHelpz
3131
{
32+
private static bool? useIntegratedSecurity;
33+
3234
public static IMsSqlDatabase CreateDatabase(string label, bool dropOnDispose = true)
3335
{
3436
var connectionString = CreateConnectionString(label);
@@ -64,16 +66,47 @@ public static MsSqlConnectionString CreateConnectionString(string label)
6466
else
6567
{
6668
connectionStringBuilder.IntegratedSecurity = true;
69+
70+
// Try to use default sql login/password specified in docker-compose.local.yml - for running integration tests locally
71+
// without locally installed MS SQL server
72+
if (useIntegratedSecurity == null)
73+
{
74+
useIntegratedSecurity = IsGoodConnectionString(connectionStringBuilder.ConnectionString);
75+
}
76+
77+
if (!useIntegratedSecurity.Value)
78+
{
79+
connectionStringBuilder.IntegratedSecurity = false;
80+
connectionStringBuilder.UserID = "sa";
81+
connectionStringBuilder.Password = "Password12!";
82+
}
6783
}
6884

6985
Console.WriteLine($"Using connection string for tests: {connectionStringBuilder.ConnectionString}");
7086

7187
return new MsSqlConnectionString(connectionStringBuilder.ConnectionString);
7288
}
7389

90+
private static bool IsGoodConnectionString(string connectionString)
91+
{
92+
try
93+
{
94+
using (var db = new SqlConnection(connectionString))
95+
{
96+
db.Open();
97+
}
98+
99+
return true;
100+
}
101+
catch (SqlException)
102+
{
103+
return false;
104+
}
105+
}
106+
74107
private static string FirstNonEmpty(params string[] parts)
75108
{
76109
return parts.First(s => !string.IsNullOrEmpty(s));
77110
}
78111
}
79-
}
112+
}

docker-compose.local.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Please note, some of the services can be installed on your machine
2+
3+
version: '2.4'
4+
5+
services:
6+
7+
# If you have MS SQL Server installed locally you can comment this service or bind on different port
8+
mssql:
9+
image: mcr.microsoft.com/mssql/server:2017-latest
10+
container_name: mssql-ef
11+
environment:
12+
ACCEPT_EULA: Y
13+
SA_PASSWORD: Password12!
14+
ports:
15+
- "1433:1433"
16+
17+
elasticsearch:
18+
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.3
19+
container_name: elasticsearch-ef
20+
environment:
21+
- discovery.type=single-node
22+
- ES_JAVA_OPTS=-Xms1g -Xmx1g
23+
ports:
24+
- "9200:9200"
25+
- "9300:9300"
26+
mem_limit: 4g
27+
28+
rabbitmq:
29+
image: rabbitmq:3-management-alpine
30+
container_name: rabbitmq-ef
31+
ports:
32+
- "5672:5672"
33+
- "15672:15672"
34+
35+
eventstore:
36+
image: eventstore/eventstore:release-4.1.3
37+
container_name: eventstore-ef
38+
ports:
39+
- "1113:1113"
40+
- "2113:2113"
41+
42+
postgres:
43+
image: postgres:10
44+
environment:
45+
POSTGRES_USER: postgres
46+
POSTGRES_PASSWORD: Password12!
47+
ports:
48+
- "5432:5432"

up_integration-test-local-env.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Up containers
2+
docker-compose --compatibility -f docker-compose.local.yml pull
3+
docker-compose --compatibility -f docker-compose.local.yml up

0 commit comments

Comments
 (0)