Skip to content

Commit

Permalink
Merge branch 'main' into pse/remove-old-workshops
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn authored Sep 14, 2024
2 parents 741dbe6 + 57035c9 commit 3b653f8
Show file tree
Hide file tree
Showing 145 changed files with 1,851 additions and 688 deletions.
81 changes: 19 additions & 62 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
run: echo "matrix=$(jq -c . < ./matrix.json)" >> $GITHUB_OUTPUT

library-tests:
name: Cover ${{ matrix.name }}
name: Run ${{ matrix.name }}
runs-on: ubuntu-latest
needs: [configure, check-changes]
if: needs.check-changes.outputs.library_changes == 'true'
Expand Down Expand Up @@ -189,88 +189,43 @@ jobs:
run: dotnet build ${{ matrix.path }} --framework net8.0 --verbosity q
timeout-minutes: 5

- name: Create directory for test results
run: mkdir -p ./.test-results

- name: Run tests
id: run-tests
timeout-minutes: 15
continue-on-error: false
run: |
dotnet test ${{ matrix.path }} --no-build --framework net8.0 --verbosity q /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=./.coverage/${{ matrix.name }}.xml --logger "trx;LogFileName=./.test-results/${{ matrix.name }}.trx" /p:ExcludeByFile="**/test/**"
run: >
dotnet test ${{ matrix.path }}
--collect:"XPlat Code Coverage;Format=opencover"
--framework net8.0
--logger trx
--no-build
--
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByFile="**/test/**"
env:
CI_BUILD: true

- name: Copy test results
continue-on-error: true
run: |
mkdir -p ./output/coverage
mkdir -p ./output/test-results
cp "${{ matrix.directoryPath }}/.coverage/${{ matrix.name }}.net8.0.xml" ./output/coverage/
cp "${{ matrix.directoryPath }}/.test-results/${{ matrix.name }}.trx" ./output/test-results/
- name: Upload Test Results as Artifacts
- name: Upload Test Results as Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.name }}
path: ./output/test-results/*.trx
path: ${{ matrix.directoryPath }}/TestResults/*.trx

- name: Upload Coverage Files as Artifacts
- name: Upload Coverage File as Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.name }}
path: ./output/coverage/*.xml
# The * matches a single directory that is named with a GUID.
# Take note of https://github.com/microsoft/vstest/issues/2334.
path: ${{ matrix.directoryPath }}/TestResults/*/coverage.opencover.xml

- name: Upload mismatch files as Artifacts
- name: Upload mismatch files as Artifact
if: steps.run-tests.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: mismatch-files-${{ matrix.name }}
path: |
**/__mismatch__/*
library-tests-no-coverage:
name: Run ${{ matrix.name }}
runs-on: ubuntu-latest
needs: [configure, check-changes]
if: needs.check-changes.outputs.library_changes == 'true'

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
show-progress: false

- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.x
7.x
8.x
- name: Run Build
id: run-build
run: dotnet build ${{ matrix.path }} --framework net8.0 --verbosity q
timeout-minutes: 5

- name: Create directory for test results
run: mkdir -p ./.test-results

- name: Run tests
id: run-tests
timeout-minutes: 15
continue-on-error: false
run: |
dotnet test ${{ matrix.path }} --no-build --framework net8.0
env:
CI_BUILD: true
path: ${{ matrix.directoryPath }}/**/__mismatch__/*

merge-coverage:
name: Merge and Upload Coverage
Expand Down Expand Up @@ -305,6 +260,7 @@ jobs:
uses: actions/download-artifact@v4
with:
path: ./output/download
pattern: coverage-*

- name: Merge Coverage Files
if: ${{ !cancelled() }}
Expand All @@ -325,6 +281,7 @@ jobs:
name: graphql-platform
flags: unittests
fail_ci_if_error: true
disable_search: true

ci-status-check:
name: "CI Status Check"
Expand Down
42 changes: 24 additions & 18 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,43 +64,47 @@ jobs:
- name: Run Build
id: run-build
run: dotnet build ${{ matrix.path }} --framework net7.0 --verbosity q
run: dotnet build ${{ matrix.path }} --framework net8.0 --verbosity q
timeout-minutes: 5

- name: Run tests
id: run-tests
timeout-minutes: 15
continue-on-error: true
run: dotnet test ${{ matrix.path }} --no-build --framework net7.0 --verbosity q /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=./.coverage/${{ matrix.name }}.xml --logger "trx;LogFileName=./.test-results/${{ matrix.name }}.trx" /p:ExcludeByFile="**/test/**"
run: >
dotnet test ${{ matrix.path }}
--collect:"XPlat Code Coverage;Format=opencover"
--framework net8.0
--logger trx
--no-build
--verbosity q
--
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByFile="**/test/**"
env:
CI_BUILD: true

- name: Upload Test Results as Artifacts
- name: Upload Test Results as Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.name }}
path: ./.test-results/*.trx
path: ${{ matrix.directoryPath }}/TestResults/*.trx

- name: Upload mismatch files as Artifacts
if: failure()
- name: Upload Coverage File as Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: mismatch-files-${{ matrix.name }}
path: |
**/__mismatch__/*
- name: Copy test results
continue-on-error: true
run: |
mkdir -p ./output/coverage
cp "${{ matrix.directoryPath }}/.coverage/${{ matrix.name }}.net7.0.xml" ./output/coverage/
name: coverage-${{ matrix.name }}
# The * matches a single directory that is named with a GUID.
# Take note of https://github.com/microsoft/vstest/issues/2334.
path: ${{ matrix.directoryPath }}/TestResults/*/coverage.opencover.xml

- name: Upload Individual Coverage Files as Artifacts
- name: Upload mismatch files as Artifact
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.name }}
path: ./output/coverage/*.xml
name: mismatch-files-${{ matrix.name }}
path: ${{ matrix.directoryPath }}/**/__mismatch__/*

- name: Fail if tests failed or were cancelled
run: exit 1
Expand Down Expand Up @@ -139,6 +143,7 @@ jobs:
uses: actions/download-artifact@v4
with:
path: ./output/download
pattern: coverage-*

- name: Merge Coverage Files
if: ${{ !cancelled() }}
Expand All @@ -159,3 +164,4 @@ jobs:
name: graphql-platform
flags: unittests
fail_ci_if_error: true
disable_search: true
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static ValueTask<IRequestExecutor> CreateExceptionExecutor(
{
context.Result =
OperationResultBuilder
.FromResult(context.Result!.ExpectSingleResult())
.FromResult(context.Result!.ExpectOperationResult())
.SetContextData("ex", queryString)
.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild">
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageVersion Include="BananaCakePop.Middleware" Version="$(BananaCakePopVersion)" />
<PackageVersion Include="Basic.Reference.Assemblies" Version="1.6.0" />
<PackageVersion Include="ChilliCream.Testing.Utilities" Version="0.2.0" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="DiffPlex" Version="1.7.2" />
<PackageVersion Include="FsCheck.Xunit" Version="3.0.0-rc3" />
<PackageVersion Include="FSharp.Core" Version="8.0.100" />
Expand Down
2 changes: 1 addition & 1 deletion src/GreenDonut/src/Core/IPromiseCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public interface IPromiseCache
/// <typeparam name="T">
/// The value type.
/// </typeparam>
void PublishMany<T>(IReadOnlyList<T> values);
void PublishMany<T>(ReadOnlySpan<T> values);

/// <summary>
/// Subscribes to the cache and gets notified when a new task is added.
Expand Down
28 changes: 16 additions & 12 deletions src/GreenDonut/src/Core/PromiseCache.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;

namespace GreenDonut;

Expand Down Expand Up @@ -174,36 +173,43 @@ public void Publish<T>(T value)
}

/// <inheritdoc />
public void PublishMany<T>(IReadOnlyList<T> values)
public void PublishMany<T>(ReadOnlySpan<T> values)
{
var buffer = ArrayPool<Promise<T>>.Shared.Rent(values.Count);
var span = buffer.AsSpan().Slice(values.Count);

var buffer = ArrayPool<Promise<T>>.Shared.Rent(values.Length);
var bufferedPromises = buffer.AsSpan().Slice(0, values.Length);

// first we add the promises tp the promise list, which we keep
// for DataLoader that are not instantiated yet.
// for this we need a quick lock as the list is shared.
// once a DataLoader instantiate it can replay all promises that
// were published before.
lock (_promises)
{
for (var i = 0; i < values.Count; i++)
for (var i = 0; i < values.Length; i++)
{
var promise = Promise<T>.Create(values[i], cloned: true);
span[i] = promise;
bufferedPromises[i] = promise;
_promises.Add(promise);
}
}

// now we notify all subscribers that are interested in the current promise type.
if (_subscriptions.TryGetValue(typeof(T), out var subscriptions))
{
foreach (var subscription in subscriptions)
{
if (subscription is Subscription<T> casted)
{
for (var i = 0; i < span.Length; i++)
for (var i = 0; i < bufferedPromises.Length; i++)
{
casted.OnNext(span[i]);
casted.OnNext(bufferedPromises[i]);
}
}
}
}

span.Clear();
// last we clear the buffer and return it to the pool.
bufferedPromises.Clear();
ArrayPool<Promise<T>>.Shared.Return(buffer);
}

Expand Down Expand Up @@ -332,7 +338,6 @@ private Entry AddNewEntry(PromiseCacheKey key, IPromise promise)
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ClearSpaceForNewEntryUnsafe()
{
while (_head is not null && _usage > _size)
Expand All @@ -343,7 +348,6 @@ private void ClearSpaceForNewEntryUnsafe()
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void TouchEntryUnsafe(Entry touched)
{
if (_order > _usage || _head == touched)
Expand Down
2 changes: 1 addition & 1 deletion src/GreenDonut/test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="ChilliCream.Testing.Utilities" />
<PackageReference Include="coverlet.msbuild">
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="ChilliCream.Testing.Utilities" />
<PackageReference Include="coverlet.msbuild">
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/HotChocolate/AspNetCore/test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild">
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/HotChocolate/AzureFunctions/test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="ChilliCream.Testing.Utilities" />
<PackageReference Include="coverlet.msbuild">
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async ValueTask InvokeAsync(IRequestContext context)
}

// only single operation results can be cached.
var operationResult = context.Result?.ExpectSingleResult();
var operationResult = context.Result?.ExpectOperationResult();

if (operationResult is { Errors: null })
{
Expand Down
2 changes: 1 addition & 1 deletion src/HotChocolate/Caching/test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="ChilliCream.Testing.Utilities" />
<PackageReference Include="coverlet.msbuild">
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static bool IsStreamResult(this IExecutionResult result)
/// <summary>
/// Expects a single GraphQL operation result.
/// </summary>
public static OperationResult ExpectSingleResult(this IExecutionResult result)
public static OperationResult ExpectOperationResult(this IExecutionResult result)
{
if (result is OperationResult qr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ private T CoerceArgumentValue<T>(ArgumentValue argument)
return default!;
}

if (value is IOptional optional)
{
return (T)optional.Value!;
}

if (value is T castedValue ||
_operationContext.Converter.TryConvert(value, out castedValue))
{
Expand Down
Loading

0 comments on commit 3b653f8

Please sign in to comment.