Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/branches-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Branch workflow (Ubuntu)
on:
push:
branches-ignore:
- develop
- 'release/**'
- 'releases/**'
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
generateVersionInfo:
name: GenerateVersionInfo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Restore dotnet tools
run: dotnet tool restore
- name: Fetch complete repository
run: git fetch
- name: Generate version info from git history
run: dotnet gitversion /output json > gitversion.json
- name: Upload version info file
uses: actions/upload-artifact@v1
with:
name: gitversion
path: gitversion.json

build:
name: Build
needs: generateVersionInfo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download version info file
uses: actions/download-artifact@v1
with:
name: gitversion
path: ./
- name: Inject version info into environment
run: jq -r 'to_entries|map("::set-env name=GitVersion_\(.key)::\(.value|tostring)")|.[]' gitversion.json
- name: Build solution
run: echo "Current version is \"$GitVersion_SemVer\"" && dotnet build -c Release
- name: Create NuGet packages
run: dotnet pack -c Release --no-build -o nupkg
- name: Upload nuget packages
uses: actions/upload-artifact@v1
with:
name: nupkg
path: nupkg

test:
name: Test
needs: [build, generateVersionInfo]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download version info file
uses: actions/download-artifact@v1
with:
name: gitversion
path: ./
- name: Inject version info into environment
run: jq -r 'to_entries|map("::set-env name=GitVersion_\(.key)::\(.value|tostring)")|.[]' gitversion.json
- name: Run tests
run: echo "Current version is \"$GitVersion_SemVer\"" && dotnet test -c Release
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Branch workflow
on:
on:
push:
branches-ignore:
- develop
- 'release/**'
- 'releases/**'
- '**'
jobs:
generateVersionInfo:
name: GenerateVersionInfo
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/main-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Main workflow (Ubuntu)
on:
push:
branches:
- develop
- 'release/**'
- 'releases/**'
tags:
- v*
- V*
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
generateVersionInfo:
name: GenerateVersionInfo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Restore dotnet tools
run: dotnet tool restore
- name: Fetch complete repository
run: git fetch
- name: Generate version info from git history
run: dotnet gitversion /output json > gitversion.json
- name: Upload version info file
uses: actions/upload-artifact@v1
with:
name: gitversion
path: gitversion.json

build:
name: Build
needs: generateVersionInfo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download version info file
uses: actions/download-artifact@v1
with:
name: gitversion
path: ./
- name: Inject version info into environment
run: jq -r 'to_entries|map("::set-env name=GitVersion_\(.key)::\(.value|tostring)")|.[]' gitversion.json
- name: Build solution
run: echo "Current version is \"$GitVersion_SemVer\"" && dotnet build -c Release
- name: Create NuGet packages
run: dotnet pack -c Release --no-build -o nupkg
- name: Upload nuget packages
uses: actions/upload-artifact@v1
with:
name: nupkg
path: nupkg

test:
name: Test
needs: [build, generateVersionInfo]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download version info file
uses: actions/download-artifact@v1
with:
name: gitversion
path: ./
- name: Inject version info into environment
run: jq -r 'to_entries|map("::set-env name=GitVersion_\(.key)::\(.value|tostring)")|.[]' gitversion.json
- name: Run tests
run: echo "Current version is \"$GitVersion_SemVer\"" && dotnet test -c Release

publish:
name: Publish
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download nuget packages
uses: actions/download-artifact@v1
with:
name: nupkg
- name: Publish the package to GPR
# using workaround with CURL because of non-functioning upload via dotnet nuget (https://stackoverflow.com/a/58943251)
run: |
for f in ./nupkg/*.nupkg
do
curl -vX PUT -u "graphql-dotnet:${{secrets.GITHUB_TOKEN}}" -F package=@$f https://nuget.pkg.github.com/graphql-dotnet/
done
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
name: Main workflow
on:
on:
push:
branches:
- develop
- 'release/**'
- 'releases/**'
tags:
- v*
- V*
branches-ignore:
- '**'
jobs:
generateVersionInfo:
name: GenerateVersionInfo
Expand Down
4 changes: 1 addition & 3 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
branches:
release:
mode: ContinuousDeployment
mode: ContinuousDeployment
7 changes: 3 additions & 4 deletions GraphQL.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Server.Test", "tests\GraphQL.Server.Test\GraphQL.Server.Test.csproj", "{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{C42106CF-F685-4F29-BC18-A70616BD68A0}"
ProjectSection(SolutionItems) = preProject
.github\FUNDING.yml = .github\FUNDING.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{05CAF9B2-981E-40C0-AE31-5FA56E351F12}"
ProjectSection(SolutionItems) = preProject
.github\workflows\branches-ubuntu.yml = .github\workflows\branches-ubuntu.yml
.github\workflows\branches.yml = .github\workflows\branches.yml
.github\workflows\main.yml = .github\workflows\main.yml
EndProjectSection
Expand Down Expand Up @@ -68,7 +66,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Client.Serializer.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Client.Tests.Common", "tests\GraphQL.Client.Tests.Common\GraphQL.Client.Tests.Common.csproj", "{0D307BAD-27AE-4A5D-8764-4AA2620B01E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQL.Client.Serializer.SystemTextJson", "src\GraphQL.Client.Serializer.SystemTextJson\GraphQL.Client.Serializer.SystemTextJson.csproj", "{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Client.Serializer.SystemTextJson", "src\GraphQL.Client.Serializer.SystemTextJson\GraphQL.Client.Serializer.SystemTextJson.csproj", "{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -138,6 +136,7 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
{05CAF9B2-981E-40C0-AE31-5FA56E351F12} = {C42106CF-F685-4F29-BC18-A70616BD68A0}
{95D78D57-3232-491D-BAD6-F373D76EA34D} = {D61415CA-D822-43DD-9AE7-993B8B60E855}
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6} = {47C98B55-08F1-4428-863E-2C5C876DEEFE}
{C212983F-67DB-44EB-BFB0-5DA75A86DF55} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
Expand Down
4 changes: 4 additions & 0 deletions src/GraphQL.Client/GraphQL.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
Expand All @@ -38,4 +39,7 @@
<ProjectReference Include="..\GraphQL.Client.Serializer.Newtonsoft\GraphQL.Client.Serializer.Newtonsoft.csproj" />
</ItemGroup>




</Project>
10 changes: 5 additions & 5 deletions tests/GraphQL.Client.Tests.Common/Helpers/ObservableTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using FluentAssertions.Primitives;

namespace GraphQL.Client.Tests.Common.Helpers {
public class ObservableTester<TPayload> : IDisposable {
public class ObservableTester<TSubscriptionPayload> : IDisposable {
private readonly IDisposable subscription;
private readonly ManualResetEventSlim updateReceived = new ManualResetEventSlim();
private readonly ManualResetEventSlim completed = new ManualResetEventSlim();
Expand All @@ -25,15 +25,15 @@ public class ObservableTester<TPayload> : IDisposable {
/// <summary>
/// The last payload which was received.
/// </summary>
public TPayload LastPayload { get; private set; }
public TSubscriptionPayload LastPayload { get; private set; }

public Exception Error { get; private set; }

/// <summary>
/// Creates a new <see cref="ObservableTester{T}"/> which subscribes to the supplied <see cref="IObservable{T}"/>
/// </summary>
/// <param name="observable">the <see cref="IObservable{T}"/> under test</param>
public ObservableTester(IObservable<TPayload> observable) {
public ObservableTester(IObservable<TSubscriptionPayload> observable) {
subscription = observable.ObserveOn(TaskPoolScheduler.Default).Subscribe(
obj => {
LastPayload = obj;
Expand All @@ -59,8 +59,8 @@ public void Dispose() {
subscription?.Dispose();
}

public SubscriptionAssertions<TPayload> Should() {
return new SubscriptionAssertions<TPayload>(this);
public SubscriptionAssertions<TSubscriptionPayload> Should() {
return new SubscriptionAssertions<TSubscriptionPayload>(this);
}

public class SubscriptionAssertions<TPayload> : ReferenceTypeAssertions<ObservableTester<TPayload>, SubscriptionAssertions<TPayload>> {
Expand Down
94 changes: 50 additions & 44 deletions tests/GraphQL.Integration.Tests/WebsocketTests/Base.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using GraphQL.Client.Abstractions;
using GraphQL.Client.Abstractions.Websocket;
Expand Down Expand Up @@ -247,49 +247,55 @@ public async void CanHandleConnectionTimeout() {
return TimeSpan.Zero;
};

var statusMonitor = client.WebsocketConnectionState.Monitor();
statusMonitor.Should().HaveReceivedPayload().Which.Should()
.Be(GraphQLWebsocketConnectionState.Disconnected);

Debug.WriteLine("creating subscription stream");
IObservable<GraphQLResponse<MessageAddedSubscriptionResult>> observable = client.CreateSubscriptionStream<MessageAddedSubscriptionResult>(SubscriptionRequest, errorMonitor.Invoke);

Debug.WriteLine("subscribing...");
var tester = observable.Monitor();
statusMonitor.Should().HaveReceivedPayload().Which.Should()
.Be(GraphQLWebsocketConnectionState.Connecting);
statusMonitor.Should().HaveReceivedPayload().Which.Should()
.Be(GraphQLWebsocketConnectionState.Connected);
callbackMonitor.Should().HaveBeenInvokedWithPayload();
const string message1 = "Hello World";

var response = await client.AddMessageAsync(message1).ConfigureAwait(false);
response.Data.AddMessage.Content.Should().Be(message1);
tester.Should().HaveReceivedPayload()
.Which.Data.MessageAdded.Content.Should().Be(message1);

Debug.WriteLine("stopping web host...");
await server.StopAsync(CancellationToken.None).ConfigureAwait(false);
server.Dispose();
Debug.WriteLine("web host stopped...");

errorMonitor.Should().HaveBeenInvokedWithPayload(TimeSpan.FromSeconds(10))
.Which.Should().BeOfType<WebSocketException>();
statusMonitor.Should().HaveReceivedPayload().Which.Should()
.Be(GraphQLWebsocketConnectionState.Disconnected);

server = CreateServer(port);
reconnectBlocker.Set();
statusMonitor.Should().HaveReceivedPayload(TimeSpan.FromSeconds(10)).Which.Should()
.Be(GraphQLWebsocketConnectionState.Connecting);
statusMonitor.Should().HaveReceivedPayload(TimeSpan.FromSeconds(10)).Which.Should()
.Be(GraphQLWebsocketConnectionState.Connected);
callbackMonitor.Should().HaveBeenInvokedWithPayload();

// disposing the client should complete the subscription
client.Dispose();
tester.Should().HaveCompleted(TimeSpan.FromSeconds(5));
server.Dispose();
var websocketStates = new ConcurrentQueue<GraphQLWebsocketConnectionState>();

using (client.WebsocketConnectionState.Subscribe(websocketStates.Enqueue)) {
websocketStates.Should().ContainSingle(state => state == GraphQLWebsocketConnectionState.Disconnected);

Debug.WriteLine("creating subscription stream");
IObservable<GraphQLResponse<MessageAddedSubscriptionResult>> observable =
client.CreateSubscriptionStream<MessageAddedSubscriptionResult>(SubscriptionRequest,
errorMonitor.Invoke);

Debug.WriteLine("subscribing...");
var tester = observable.Monitor();
callbackMonitor.Should().HaveBeenInvokedWithPayload();

websocketStates.Should().ContainInOrder(
GraphQLWebsocketConnectionState.Disconnected,
GraphQLWebsocketConnectionState.Connecting,
GraphQLWebsocketConnectionState.Connected);
// clear the collection so the next tests on the collection work as expected
websocketStates.Clear();

const string message1 = "Hello World";
var response = await client.AddMessageAsync(message1).ConfigureAwait(false);
response.Data.AddMessage.Content.Should().Be(message1);
tester.Should().HaveReceivedPayload()
.Which.Data.MessageAdded.Content.Should().Be(message1);

Debug.WriteLine("stopping web host...");
await server.StopAsync(CancellationToken.None).ConfigureAwait(false);
server.Dispose();
Debug.WriteLine("web host stopped...");

errorMonitor.Should().HaveBeenInvokedWithPayload(TimeSpan.FromSeconds(10))
.Which.Should().BeOfType<WebSocketException>();
websocketStates.Should().Contain(GraphQLWebsocketConnectionState.Disconnected);

server = CreateServer(port);
reconnectBlocker.Set();
callbackMonitor.Should().HaveBeenInvokedWithPayload();
websocketStates.Should().ContainInOrder(
GraphQLWebsocketConnectionState.Disconnected,
GraphQLWebsocketConnectionState.Connecting,
GraphQLWebsocketConnectionState.Connected);

// disposing the client should complete the subscription
client.Dispose();
tester.Should().HaveCompleted(TimeSpan.FromSeconds(5));
server.Dispose();
}
}


Expand Down