Skip to content

Commit 3759fda

Browse files
authored
Merge pull request #1105 from glucaci/fixMongoIndex
Fix MongoDB index for GetRunnableInstances
2 parents 97974b2 + 53143d4 commit 3759fda

38 files changed

+238
-250
lines changed

.github/workflows/dotnet.yml

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ on:
77
branches: [ master ]
88

99
jobs:
10-
build:
11-
10+
Unit-Tests:
1211
runs-on: ubuntu-latest
13-
1412
steps:
1513
- uses: actions/checkout@v2
1614
- name: Setup .NET
@@ -25,13 +23,99 @@ jobs:
2523
run: dotnet build --no-restore
2624
- name: Unit Tests
2725
run: dotnet test test/WorkflowCore.UnitTests --no-build --verbosity normal -p:ParallelizeTestCollections=false
28-
- name: Integration Tests
29-
run: dotnet test test/WorkflowCore.IntegrationTests --no-build --verbosity normal -p:ParallelizeTestCollections=false
30-
- name: PostgreSQL Tests
31-
run: dotnet test test/WorkflowCore.Tests.PostgreSQL --no-build --verbosity normal -p:ParallelizeTestCollections=false
32-
- name: Redis Tests
33-
run: dotnet test test/WorkflowCore.Tests.Redis --no-build --verbosity normal -p:ParallelizeTestCollections=false
34-
- name: SQL Server Tests
35-
run: dotnet test test/WorkflowCore.Tests.SqlServer --no-build --verbosity normal -p:ParallelizeTestCollections=false
36-
- name: Elasticsearch Tests
37-
run: dotnet test test/WorkflowCore.Tests.Elasticsearch --no-build --verbosity normal -p:ParallelizeTestCollections=false
26+
Integration-Tests:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v2
30+
- name: Setup .NET
31+
uses: actions/setup-dotnet@v1
32+
with:
33+
dotnet-version: |
34+
3.1.x
35+
6.0.x
36+
- name: Restore dependencies
37+
run: dotnet restore
38+
- name: Build
39+
run: dotnet build --no-restore
40+
- name: Integration Tests
41+
run: dotnet test test/WorkflowCore.IntegrationTests --no-build --verbosity normal -p:ParallelizeTestCollections=false
42+
MongoDB-Tests:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v2
46+
- name: Setup .NET
47+
uses: actions/setup-dotnet@v1
48+
with:
49+
dotnet-version: |
50+
3.1.x
51+
6.0.x
52+
- name: Restore dependencies
53+
run: dotnet restore
54+
- name: Build
55+
run: dotnet build --no-restore
56+
- name: MongoDB Tests
57+
run: dotnet test test/WorkflowCore.Tests.MongoDB --no-build --verbosity normal -p:ParallelizeTestCollections=false
58+
PostgreSQL-Tests:
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v2
62+
- name: Setup .NET
63+
uses: actions/setup-dotnet@v1
64+
with:
65+
dotnet-version: |
66+
3.1.x
67+
6.0.x
68+
- name: Restore dependencies
69+
run: dotnet restore
70+
- name: Build
71+
run: dotnet build --no-restore
72+
- name: PostgreSQL Tests
73+
run: dotnet test test/WorkflowCore.Tests.PostgreSQL --no-build --verbosity normal -p:ParallelizeTestCollections=false
74+
Redis-Tests:
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v2
78+
- name: Setup .NET
79+
uses: actions/setup-dotnet@v1
80+
with:
81+
dotnet-version: |
82+
3.1.x
83+
6.0.x
84+
- name: Restore dependencies
85+
run: dotnet restore
86+
- name: Build
87+
run: dotnet build --no-restore
88+
- name: Redis Tests
89+
run: dotnet test test/WorkflowCore.Tests.Redis --no-build --verbosity normal -p:ParallelizeTestCollections=false
90+
SQLServer-Tests:
91+
runs-on: ubuntu-latest
92+
steps:
93+
- uses: actions/checkout@v2
94+
- name: Setup .NET
95+
uses: actions/setup-dotnet@v1
96+
with:
97+
dotnet-version: |
98+
3.1.x
99+
6.0.x
100+
- name: Restore dependencies
101+
run: dotnet restore
102+
- name: Build
103+
run: dotnet build --no-restore
104+
- name: SQL Server Tests
105+
run: dotnet test test/WorkflowCore.Tests.SqlServer --no-build --verbosity normal -p:ParallelizeTestCollections=false
106+
Elasticsearch-Tests:
107+
runs-on: ubuntu-latest
108+
steps:
109+
- uses: actions/checkout@v2
110+
- name: Setup .NET
111+
uses: actions/setup-dotnet@v1
112+
with:
113+
dotnet-version: |
114+
3.1.x
115+
6.0.x
116+
- name: Restore dependencies
117+
run: dotnet restore
118+
- name: Build
119+
run: dotnet build --no-restore
120+
- name: Elasticsearch Tests
121+
run: dotnet test test/WorkflowCore.Tests.Elasticsearch --no-build --verbosity normal -p:ParallelizeTestCollections=false

src/providers/WorkflowCore.Persistence.MongoDB/Services/MongoPersistenceProvider.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ static void CreateIndexes(MongoPersistenceProvider instance)
9393
if (!indexesCreated)
9494
{
9595
instance.WorkflowInstances.Indexes.CreateOne(new CreateIndexModel<WorkflowInstance>(
96-
Builders<WorkflowInstance>.IndexKeys.Ascending(x => x.NextExecution),
97-
new CreateIndexOptions {Background = true, Name = "idx_nextExec"}));
96+
Builders<WorkflowInstance>.IndexKeys
97+
.Ascending(x => x.NextExecution)
98+
.Ascending(x => x.Status)
99+
.Ascending(x => x.Id),
100+
new CreateIndexOptions {Background = true, Name = "idx_nextExec_v2"}));
98101

99102
instance.Events.Indexes.CreateOne(new CreateIndexModel<Event>(
100103
Builders<Event>.IndexKeys.Ascending(x => x.IsProcessed),

test/Directory.Build.props

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,21 @@
44
<LangVersion>latest</LangVersion>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0"/>
10+
<PackageReference Include="xunit" Version="2.4.1"/>
11+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"/>
12+
<PackageReference Include="FluentAssertions" Version="4.19.4" />
13+
<PackageReference Include="Moq" Version="4.7.145" />
14+
<PackageReference Include="FakeItEasy" Version="4.9.2" />
15+
</ItemGroup>
16+
17+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
18+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.2" />
19+
</ItemGroup>
20+
21+
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
22+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
23+
</ItemGroup>
724
</Project>

test/ScratchPad/ScratchPad.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
88
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
99
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
10+
<GenerateProgramFile>false</GenerateProgramFile>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

test/WorkflowCore.IntegrationTests/WorkflowCore.IntegrationTests.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818

1919
<ItemGroup>
2020
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.1" />
21-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
22-
<PackageReference Include="FluentAssertions" Version="4.19.4" />
23-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
24-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
25-
<PackageReference Include="Moq" Version="4.7.145" />
26-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
27-
<PackageReference Include="xunit" Version="2.3.1" />
28-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
2921
</ItemGroup>
3022

3123
<ItemGroup>

test/WorkflowCore.TestAssets/WorkflowCore.TestAssets.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<PackageReference Include="FluentAssertions" Version="4.19.4" />
42-
<PackageReference Include="Moq" Version="4.7.145" />
4341
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
4442
<PackageReference Include="NUnit" Version="3.6.1" />
4543
</ItemGroup>

test/WorkflowCore.Tests.DynamoDB/WorkflowCore.Tests.DynamoDB.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
<ItemGroup>
44
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.3.11" />
5-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
6-
<PackageReference Include="xunit" Version="2.4.0" />
7-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
85
</ItemGroup>
96

107
<ItemGroup>
Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,34 @@
11
using System;
2-
using System.Collections.Generic;
3-
using Docker.Testify;
4-
using Nest;
2+
using System.Threading.Tasks;
3+
using Squadron;
54
using Xunit;
65

76
namespace WorkflowCore.Tests.Elasticsearch
87
{
9-
public class ElasticsearchDockerSetup : DockerSetup
8+
public class ElasticsearchDockerSetup : IAsyncLifetime
109
{
10+
private readonly ElasticsearchResource _elasticsearchResource;
1111
public static string ConnectionString { get; set; }
12-
13-
public override string ImageName => @"elasticsearch";
14-
public override string ImageTag => "7.5.1";
15-
public override int InternalPort => 9200;
16-
public override TimeSpan TimeOut => TimeSpan.FromSeconds(30);
17-
18-
public override IList<string> EnvironmentVariables => new List<string> {
19-
$"discovery.type=single-node"
20-
};
2112

22-
public override void PublishConnectionInfo()
13+
public ElasticsearchDockerSetup()
2314
{
24-
ConnectionString = $"http://localhost:{ExternalPort}";
15+
_elasticsearchResource = new ElasticsearchResource();
2516
}
2617

27-
public override bool TestReady()
18+
public async Task InitializeAsync()
2819
{
29-
try
30-
{
31-
var client = new ElasticClient(new ConnectionSettings(new Uri($"http://localhost:{ExternalPort}")));
32-
var ping = client.Ping();
33-
return ping.IsValid;
34-
}
35-
catch
36-
{
37-
return false;
38-
}
20+
await _elasticsearchResource.InitializeAsync();
21+
ConnectionString = $"http://localhost:{_elasticsearchResource.Instance.HostPort}";
22+
}
3923

24+
public Task DisposeAsync()
25+
{
26+
return _elasticsearchResource.DisposeAsync();
4027
}
4128
}
4229

4330
[CollectionDefinition("Elasticsearch collection")]
4431
public class ElasticsearchCollection : ICollectionFixture<ElasticsearchDockerSetup>
4532
{
4633
}
47-
}
34+
}

test/WorkflowCore.Tests.Elasticsearch/WorkflowCore.Tests.Elasticsearch.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
4-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
5-
<PackageReference Include="NEST" Version="7.14.1" />
6-
<PackageReference Include="xunit" Version="2.4.0" />
7-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
4+
<PackageReference Include="Squadron.Elasticsearch" Version="0.17.0" />
85
</ItemGroup>
96

107
<ItemGroup>
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
11
using System;
2-
using Docker.Testify;
3-
using MongoDB.Driver;
2+
using System.Threading.Tasks;
3+
using MongoDB.Bson;
4+
using Squadron;
45
using Xunit;
56

67
namespace WorkflowCore.Tests.MongoDB
7-
{
8-
public class MongoDockerSetup : DockerSetup
8+
{
9+
public class MongoDockerSetup : IAsyncLifetime
910
{
11+
private readonly MongoResource _mongoResource;
1012
public static string ConnectionString { get; set; }
1113

12-
public override string ImageName => "mongo";
13-
public override int InternalPort => 27017;
14-
15-
public override void PublishConnectionInfo()
14+
public MongoDockerSetup()
1615
{
17-
ConnectionString = $"mongodb://localhost:{ExternalPort}";
16+
_mongoResource = new MongoResource();
1817
}
1918

20-
public override bool TestReady()
19+
public async Task InitializeAsync()
2120
{
22-
try
23-
{
24-
var client = new MongoClient($"mongodb://localhost:{ExternalPort}");
25-
client.ListDatabases();
26-
return true;
27-
}
28-
catch
29-
{
30-
return false;
31-
}
21+
await _mongoResource.InitializeAsync();
22+
ConnectionString = _mongoResource.ConnectionString;
23+
}
3224

25+
public Task DisposeAsync()
26+
{
27+
return _mongoResource.DisposeAsync();
3328
}
3429
}
3530

3631
[CollectionDefinition("Mongo collection")]
3732
public class MongoCollection : ICollectionFixture<MongoDockerSetup>
38-
{
33+
{
3934
}
40-
41-
}
35+
}

0 commit comments

Comments
 (0)