Skip to content

Commit 0c89e9c

Browse files
committed
cancellation in disposal fix
1 parent b49e2c7 commit 0c89e9c

File tree

3 files changed

+36
-75
lines changed

3 files changed

+36
-75
lines changed

.github/workflows/publish-package.yml

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,79 +29,38 @@ jobs:
2929
name: Build
3030

3131
- name: Test
32-
id: tests
33-
continue-on-error: true # so we can always publish the report
32+
id: test
3433
run: |
35-
dotnet test test/Serilog.Sinks.XUnit.Injectable.Tests.csproj \
36-
--configuration Release \
37-
--verbosity normal \
38-
-- \
39-
--report-ctrf \
40-
--report-ctrf-filename test-results.ctrf.json
41-
echo "exitcode=$?" >> "$GITHUB_OUTPUT"
34+
dotnet test test/Serilog.Sinks.XUnit.Injectable.Tests.csproj --verbosity Normal
4235
43-
# ──────────────────────────────
44-
# 2. Upload the raw report file (keeps history)
45-
# ──────────────────────────────
46-
- name: Upload CTRF artifact
47-
if: always()
48-
uses: actions/upload-artifact@v4
49-
with:
50-
name: ctrf-report
51-
path: test-results.ctrf.json
52-
53-
# ──────────────────────────────
54-
# 3. Render the report in the job summary / PR
55-
# ──────────────────────────────
56-
- name: Publish Test Report
57-
if: always()
58-
uses: ctrf-io/github-test-reporter@v1
59-
with:
60-
report-path: test-results.ctrf.json # glob or file path is fine
61-
summary-report: true # job summary (default if no reports chosen)
62-
github-report: true # annotate PRs / Checks
63-
# add other reports as you like
64-
# ──────────────────────────────
65-
# 4. Fail the job *after* publishing if tests failed
66-
# ──────────────────────────────
67-
- name: Fail if tests failed
68-
if: steps.tests.outputs.exitcode != '0'
69-
run: exit 1
70-
71-
# ──────────────────────────────
72-
# 5. Package & publish (runs only when tests passed)
73-
# ──────────────────────────────
7436
- name: Pack
75-
if: success()
7637
run: dotnet pack --no-build --configuration Release --output .
7738

78-
- name: Publish to NuGet
79-
if: success()
80-
run: dotnet nuget push "**/*.nupkg" --source "https://api.nuget.org/v3/index.json" \
81-
--api-key "${{ secrets.NUGET__TOKEN }}" --skip-duplicate
39+
- name: Publish to nuGet
40+
run: dotnet nuget push **/*.nupkg --source 'https://api.nuget.org/v3/index.json' --api-key ${{ secrets.NUGET__TOKEN }} --skip-duplicate
8241

8342
- name: Add GitHub NuGet Source
84-
if: success()
8543
run: |
86-
dotnet nuget add source https://nuget.pkg.github.com/soenneker/index.json \
87-
--name "github" \
88-
--username "any" \
89-
--password "${{ secrets.GH__TOKEN }}" \
90-
--store-password-in-clear-text
44+
dotnet nuget add source https://nuget.pkg.github.com/soenneker/index.json \
45+
--name "github" \
46+
--username "any" \
47+
--password "${{ secrets.GH__TOKEN }}" \
48+
--store-password-in-clear-text
9149
9250
- name: Publish to GitHub Packages
93-
if: success()
94-
run: dotnet nuget push "**/*.nupkg" --source "github" --api-key "${{ secrets.GH__TOKEN }}"
51+
run: |
52+
dotnet nuget push ./*.nupkg \
53+
--source "github" \
54+
--api-key "${{ secrets.GH__TOKEN }}"
9555
9656
- name: Create GitHub Release
97-
if: success()
9857
run: |
99-
changelog=$(git log -20 --pretty=format:"- %s")
100-
tag_name="v${BUILD_VERSION}"
101-
jq -n --arg tag_name "$tag_name" --arg name "$tag_name" --arg body "$changelog" \
102-
'{tag_name:$tag_name,name:$name,body:$body,draft:false,prerelease:false}' > payload.json
103-
curl -s -X POST \
104-
-H "Authorization: Bearer ${{ secrets.GH__TOKEN }}" \
105-
-H "Accept: application/vnd.github+json" \
106-
https://api.github.com/repos/${{ github.repository }}/releases \
107-
-d @payload.json
58+
changelog=$(git log -20 --pretty=format:"- %s")
59+
tag_name="v${BUILD_VERSION}"
60+
jq -n --arg tag_name "$tag_name" --arg name "$tag_name" --arg body "$changelog" \
61+
'{tag_name:$tag_name,name:$name,body:$body,draft:false,prerelease:false}' > payload.json
62+
curl -s -X POST \
63+
-H "Authorization: Bearer ${{ secrets.GH__TOKEN }}" \
64+
-H "Accept: application/vnd.github+json" \
65+
https://api.github.com/repos/${{ github.repository }}/releases \
66+
-d @payload.json

src/Serilog.Sinks.XUnit.Injectable/InjectableTestOutputSink.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,20 @@ public async ValueTask DisposeAsync()
104104
if (Interlocked.Exchange(ref _disposed, 1) != 0)
105105
return;
106106

107-
await _cts.CancelAsync().ConfigureAwait(false);
108-
107+
// 1) Tell the reader no more items are coming
109108
_ch.Writer.TryComplete();
110109

111110
try
112111
{
112+
// 2) Let the reader finish formatting & flushing
113113
await _readerTask.ConfigureAwait(false);
114114
}
115-
catch
115+
finally
116116
{
117-
/* swallow to keep test teardown clean */
117+
// 3) Now it’s safe to cancel / dispose
118+
await _cts.CancelAsync().ConfigureAwait(false); // optional – keeps teardown symmetric
119+
_cts.Dispose();
120+
await _sw.DisposeAsync().ConfigureAwait(false);
118121
}
119-
120-
await _sw.DisposeAsync().ConfigureAwait(false);
121122
}
122123
}

test/Sinks/ChannelInjectableTestOutputSink.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,20 @@ public async ValueTask DisposeAsync()
105105
if (Interlocked.Exchange(ref _disposed, 1) != 0)
106106
return;
107107

108-
await _cts.CancelAsync().ConfigureAwait(false);
109-
108+
// 1) Tell the reader no more items are coming
110109
_ch.Writer.TryComplete();
111110

112111
try
113112
{
113+
// 2) Let the reader finish formatting & flushing
114114
await _readerTask.ConfigureAwait(false);
115115
}
116-
catch
116+
finally
117117
{
118-
/* swallow to keep test teardown clean */
118+
// 3) Now it’s safe to cancel / dispose
119+
await _cts.CancelAsync().ConfigureAwait(false); // optional – keeps teardown symmetric
120+
_cts.Dispose();
121+
await _sw.DisposeAsync().ConfigureAwait(false);
119122
}
120-
121-
await _sw.DisposeAsync().ConfigureAwait(false);
122123
}
123124
}

0 commit comments

Comments
 (0)