Skip to content
Open
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
21 changes: 20 additions & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
with:
dotnet-version: '10.0.x'

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'

- name: Cache SonarCloud packages
uses: actions/cache@v5
with:
Expand All @@ -59,6 +64,12 @@ jobs:
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: dotnet tool update dotnet-sonarscanner --tool-path .sonar/scanner

- name: Install .NET coverage collector
run: dotnet tool update dotnet-coverage --tool-path .sonar/scanner

- name: Install Python dependencies
run: python -m pip install -r roles/importer/files/importer/requirements.txt coverage==7.15.0

- name: Build and analyze
run: |
for attempt in 1 2 3; do
Expand All @@ -67,7 +78,9 @@ jobs:
/o:"${SONAR_ORGANIZATION}" \
/d:sonar.token="${SONAR_TOKEN}" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.qualitygate.wait=true; then
/d:sonar.qualitygate.wait=true \
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \
/d:sonar.python.coverage.reportPaths=python-coverage.xml; then
break
else
status=$?
Expand All @@ -81,6 +94,12 @@ jobs:
sleep $((attempt * 30))
done
dotnet build roles/FWO.sln --configuration Debug --no-incremental
.sonar/scanner/dotnet-coverage collect \
"dotnet test roles/tests-unit/files/FWO.Test/FWO.Test.csproj --configuration Debug --no-build --settings FWO.default.runsettings" \
-f xml \
-o coverage.xml
python -m coverage run -m pytest -q roles/importer/files/importer/test
python -m coverage xml -o python-coverage.xml
for attempt in 1 2 3; do
if .sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${SONAR_TOKEN}"; then
break
Expand Down
45 changes: 45 additions & 0 deletions roles/tests-unit/files/FWO.Test/PeriodicTaskRunnerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,50 @@ public async Task Dispose_StopsFurtherExecutions()

Assert.That(executionCount, Is.EqualTo(executionCountAfterDispose));
}

[Test]
public async Task Start_CalledTwice_SecondCallIsIgnored()
{
int executionCount = 0;
TaskCompletionSource<bool> firstTickReached = new(TaskCreationOptions.RunContinuationsAsynchronously);

using PeriodicTaskRunner runner = new(async () =>
{
if (Interlocked.Increment(ref executionCount) == 1)
{
firstTickReached.TrySetResult(true);
}

await Task.CompletedTask;
}, TimeSpan.FromMilliseconds(20));

runner.Start();
Assert.DoesNotThrow(runner.Start);

Task completedTask = await Task.WhenAny(firstTickReached.Task, Task.Delay(TimeSpan.FromSeconds(2)));

Assert.That(completedTask, Is.EqualTo(firstTickReached.Task));
}

[Test]
public void Dispose_CalledTwice_IsIdempotent()
{
PeriodicTaskRunner runner = new(() => Task.CompletedTask, TimeSpan.FromMilliseconds(20));

runner.Start();
runner.Dispose();

Assert.DoesNotThrow(runner.Dispose);
}

[Test]
public void Start_AfterDispose_Throws()
{
PeriodicTaskRunner runner = new(() => Task.CompletedTask, TimeSpan.FromMilliseconds(20));

runner.Dispose();

Assert.Throws<ObjectDisposedException>(runner.Start);
}
}
}
Loading