Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 4c1a7cc

Browse files
Merge pull request #68 from thefringeninja/oops-i-did-it-again
Make Sure Server Actually Starts
2 parents 07fb6f7 + 2f800f7 commit 4c1a7cc

9 files changed

Lines changed: 115 additions & 19 deletions

File tree

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ COPY ./src/*/*.csproj ./src/Directory.Build.props ./
3838

3939
RUN for file in $(ls *.csproj); do mkdir -p ./${file%.*}/ && mv $file ./${file%.*}/; done
4040

41+
WORKDIR /app/tests
42+
43+
COPY ./tests/*/*.csproj ./
44+
45+
RUN for file in $(ls *.csproj); do mkdir -p ./${file%.*}/ && mv $file ./${file%.*}/; done
46+
4147
WORKDIR /app
4248

4349
COPY ./NuGet.Config ./
@@ -50,6 +56,10 @@ COPY ./src .
5056

5157
COPY --from=build-javascript /app/node_modules/${CLIENT_PACKAGE}/build /app/src/SqlStreamStore.Server/Browser/build
5258

59+
WORKDIR /app/tests
60+
61+
COPY ./tests .
62+
5363
WORKDIR /app/build
5464

5565
COPY ./build/build.csproj .
@@ -58,6 +68,10 @@ RUN dotnet restore
5868

5969
COPY ./build .
6070

71+
WORKDIR /app/src
72+
73+
COPY ./src .
74+
6175
WORKDIR /app
6276

6377
RUN dotnet run --project build/build.csproj -- --runtime=${RUNTIME} --library-version=${LIBRARY_VERSION}

SqlStreamStore.Server.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.27130.2027
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlStreamStore.Server", "src\SqlStreamStore.Server\SqlStreamStore.Server.csproj", "{B4B24F09-CB96-4D2E-A1D2-C50C9557F144}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlStreamStore.Server.Tests", "tests\SqlStreamStore.Server.Tests\SqlStreamStore.Server.Tests.csproj", "{AE3DAADF-EE63-4CFF-9024-0730650DD165}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{B4B24F09-CB96-4D2E-A1D2-C50C9557F144}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{B4B24F09-CB96-4D2E-A1D2-C50C9557F144}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{B4B24F09-CB96-4D2E-A1D2-C50C9557F144}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{AE3DAADF-EE63-4CFF-9024-0730650DD165}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{AE3DAADF-EE63-4CFF-9024-0730650DD165}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{AE3DAADF-EE63-4CFF-9024-0730650DD165}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{AE3DAADF-EE63-4CFF-9024-0730650DD165}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-alpine3.9}
6-
LIBRARY_VERSION=${LIBRARY_VERSION:-1.2.0-beta.3.12}
6+
LIBRARY_VERSION=${LIBRARY_VERSION:-1.2.0-beta.3.19}
77
CLIENT_VERSION=${CLIENT_VERSION:-0.9.2}
88

99
LOCAL_IMAGE="sql-stream-store-server"

build/Program.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ static class Program
1212

1313
public static void Main(string[] args)
1414
{
15-
const string clean = nameof(Clean);
16-
const string build = nameof(Build);
17-
const string publish = nameof(Publish);
15+
const string clean = nameof(clean);
16+
const string build = nameof(build);
17+
const string test = nameof(test);
18+
const string publish = nameof(publish);
1819

1920
var runtime = "alpine-x64";
2021
var libraryVersion = "1.2.0-beta.*";
@@ -43,8 +44,13 @@ public static void Main(string[] args)
4344
Build(libraryVersion));
4445

4546
Target(
46-
publish,
47+
test,
4748
DependsOn(build),
49+
Test);
50+
51+
Target(
52+
publish,
53+
DependsOn(test),
4854
Publish(runtime, libraryVersion));
4955

5056
Target("default", DependsOn(publish));
@@ -69,6 +75,10 @@ private static Action Build(string libraryVersion) => () => Run(
6975
"dotnet",
7076
$"build SqlStreamStore.Server.sln --configuration=Release /p:LibraryVersion={libraryVersion}");
7177

78+
private static readonly Action Test = () => Run(
79+
"dotnet",
80+
$"test --configuration=Release --no-build");
81+
7282
private static Action Publish(string runtime, string libraryVersion) => () => Run(
7383
"dotnet",
7484
$"publish --configuration=Release --output=../../{PublishDir} --runtime={runtime} /p:ShowLinkerSizeComparison=true /p:LibraryVersion={libraryVersion} src/SqlStreamStore.Server");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("SqlStreamStore.Server.Tests")]

src/SqlStreamStore.Server/SqlStreamStore.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
66
<LangVersion>latest</LangVersion>
77
<CrossGenDuringPublish>false</CrossGenDuringPublish>
8-
<LibraryVersion Condition="$(LibraryVersion) == ''">1.2.0-beta.3.16+build.415</LibraryVersion>
8+
<LibraryVersion Condition="$(LibraryVersion) == ''">1.2.0-beta.3.19</LibraryVersion>
99
</PropertyGroup>
1010
<ItemGroup>
1111
<PackageReference Include="ILLink.Tasks" Version="0.1.5-preview-1841731" />

src/SqlStreamStore.Server/SqlStreamStoreServerStartup.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,15 @@ public SqlStreamStoreServerStartup(
3131

3232
public IServiceProvider ConfigureServices(IServiceCollection services) => services
3333
.AddResponseCompression(options => options.MimeTypes = new[] { "application/hal+json" })
34+
.AddRouting()
3435
.BuildServiceProvider();
3536

3637
public void Configure(IApplicationBuilder app) => app
3738
.UseResponseCompression()
3839
.Use(VaryAccept)
39-
.Use(CatchAndDisplayErrors)
4040
.UseSqlStreamStoreBrowser()
4141
.UseSqlStreamStoreHal(_streamStore, _options);
4242

43-
private static MidFunc CatchAndDisplayErrors => async (context, next) =>
44-
{
45-
try
46-
{
47-
await next();
48-
}
49-
catch(Exception ex)
50-
{
51-
Log.Warning(ex, "Error during request.");
52-
}
53-
};
54-
5543
private static MidFunc VaryAccept => (context, next) =>
5644
{
5745
Task Vary()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<IsPackable>false</IsPackable>
5+
<DebugType>portable</DebugType>
6+
<DebugSymbols>true</DebugSymbols>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\SqlStreamStore.Server\SqlStreamStore.Server.csproj" />
10+
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" />
13+
<PackageReference Include="xunit" Version="2.4.1" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
15+
</ItemGroup>
16+
</Project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Net.Http.Headers;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.AspNetCore.TestHost;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using SqlStreamStore;
9+
using SqlStreamStore.HAL;
10+
using SqlStreamStore.Server;
11+
using Xunit;
12+
13+
namespace SQLStreamStore.Server.Tests
14+
{
15+
public class SqlStreamStoreServerStartupTests : IDisposable
16+
{
17+
private readonly InMemoryStreamStore _streamStore;
18+
private readonly IWebHost _host;
19+
private TestServer _server;
20+
private readonly HttpClient _httpClient;
21+
22+
public SqlStreamStoreServerStartupTests()
23+
{
24+
_streamStore = new InMemoryStreamStore();
25+
26+
_server = new TestServer(
27+
new WebHostBuilder()
28+
.UseStartup(new SqlStreamStoreServerStartup(
29+
_streamStore,
30+
new SqlStreamStoreMiddlewareOptions
31+
{
32+
UseCanonicalUrls = false
33+
})));
34+
35+
_httpClient = new HttpClient(_server.CreateHandler())
36+
{
37+
BaseAddress = new UriBuilder().Uri
38+
};
39+
}
40+
41+
[Fact]
42+
public async Task StartsUp()
43+
{
44+
using (await _httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
45+
{
46+
Headers = {Accept = {new MediaTypeWithQualityHeaderValue("application/hal+json")}}
47+
}))
48+
{
49+
}
50+
}
51+
52+
public void Dispose()
53+
{
54+
_streamStore?.Dispose();
55+
_host?.Dispose();
56+
_httpClient?.Dispose();
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)