Skip to content

Commit

Permalink
- Fix, re-enable delay unit test (#27)
Browse files Browse the repository at this point in the history
- Clarify that delays are prone to small margins of error in README.md
- New setup script for installing .NET versions on Unix
  • Loading branch information
nwithan8 authored Oct 3, 2022
1 parent dd01597 commit 3c19d5d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
8 changes: 4 additions & 4 deletions EasyVCR.Tests/ClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public async Task TestDefaultRequestMatching()
}

[TestMethod]
[Ignore] // TODO: fix this test
public async Task TestDelay()
{
var cassette = TestUtils.GetCassette("test_delay");
Expand All @@ -122,7 +121,7 @@ public async Task TestDelay()

// confirm the normal replay worked, note time
Assert.IsNotNull(response);
var normalReplayTime = (int)stopwatch.ElapsedMilliseconds;
var normalReplayTime = Math.Max(0, (int)stopwatch.ElapsedMilliseconds); // sometimes stopwatch returns a negative number, let's avoid that

// set up advanced settings
var delay = normalReplayTime + 3000; // add 3 seconds to the normal replay time, for good measure
Expand All @@ -139,9 +138,10 @@ public async Task TestDelay()
response = await fakeDataService.GetIPAddressDataRawResponse();
stopwatch.Stop();

// check that the delay was respected
// check that the delay was respected (within margin of error)
Assert.IsNotNull(response);
Assert.IsTrue((int)stopwatch.ElapsedMilliseconds >= delay);
var delay95Percentile = (int)(delay * 0.95); // 5% tolerance
Assert.IsTrue((int)stopwatch.ElapsedMilliseconds >= delay95Percentile);
}

[TestMethod]
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ scan:
dotnet tool run security-scan --verbose --no-banner --ignore-msbuild-errors EasyVCR.sln
# "--ignore-msbuild-errors" needed since MSBuild does not like F#: https://github.com/security-code-scan/security-code-scan/issues/235

## setup - Install required .NET versions and tools (Windows only)
setup:
## setup-win - Install required .NET versions and tools (Windows only)
setup-win:
scripts\setup.bat

## setup-unix - Install required .NET versions and tools (Unix only)
setup-unix:
bash scripts/setup.sh

## sign - Sign all generated DLLs and NuGet packages with the provided certificate (Windows only)
# @parameters:
# cert= - The certificate to use for signing the built assets.
Expand All @@ -118,4 +122,4 @@ test-fw:
uninstall-scanner:
dotnet tool uninstall security-scan

.PHONY: help build build-test-fw build-prod clean format install-cert install-tools install lint lint-scripts pre-release publish-all publish release restore scan setup sign test test-fw uninstall-scanner
.PHONY: help build build-test-fw build-prod clean format install-cert install-tools install lint lint-scripts pre-release publish-all publish release restore scan setup-unix setup-win sign test test-fw uninstall-scanner
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ var httpClient = HttpClients.NewHttpClient(cassette, Mode.Record, advancedSettin

Simulate a delay when replaying a recorded request, either using a specified delay or the original request duration.

NOTE: Delays may suffer from a small margin of error on certain .NET versions. Do not rely on the delay being exact down to the millisecond.

**Default**: *No delay*

```csharp
Expand Down
21 changes: 21 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# This script is used to download and install the required .NET versions

# .NET versions we want to install
declare -a NetVersions=("Current" "6.0" "5.0" "3.1")

# Download dotnet-install.sh
echo "Downloading dotnet-install.sh script..."
curl -sSL https://dot.net/v1/dotnet-install.sh -o dotnet-install.sh

# Install each .NET version
echo "Installing .NET versions..."
for version in ${NetVersions[@]}; do
echo "Installing .NET $version..."
sudo bash ./dotnet-install.sh -c "$version"
done

# Remove dotnet-install.sh
echo "Removing dotnet-install.sh script..."
rm dotnet-install.sh

0 comments on commit 3c19d5d

Please sign in to comment.