Skip to content

Commit

Permalink
Remove .ConfigureAwait(false) from all tests
Browse files Browse the repository at this point in the history
To avoid xUnit's CA2007 warning
  • Loading branch information
nurhafiz committed May 1, 2024
1 parent 22a3cf9 commit b9e58a5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions tests/Toimik.WarcProtocol.Tests/RequestRecordTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task ParseWithCustomPayloadTypeIdentifierAndContentBlockThatHasNoPa
var parser = new WarcParser(recordFactory);
var path = $"{WarcParserTest.DirectoryForValidRecords}1.1{Path.DirectorySeparatorChar}misc{Path.DirectorySeparatorChar}request_gemini_wo_payload.warc";

var records = await parser.Parse(path).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path).ToListAsync();
var actualRecord = (RequestRecord)records[0];

Assert.Equal(ExpectedRecordBlock, actualRecord.RecordBlock);
Expand All @@ -109,7 +109,7 @@ public async Task ParseWithCustomPayloadTypeIdentifierAndContentBlockThatHasPayl
var parser = new WarcParser(recordFactory);
var path = $"{WarcParserTest.DirectoryForValidRecords}1.1{Path.DirectorySeparatorChar}misc{Path.DirectorySeparatorChar}request_gemini_w_payload.warc";

var records = await parser.Parse(path).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path).ToListAsync();
var actualRecord = (RequestRecord)records[0];

Assert.Equal(ExpectedRecordBlock, actualRecord.RecordBlock);
Expand Down
4 changes: 2 additions & 2 deletions tests/Toimik.WarcProtocol.Tests/ResponseRecordTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task ParseWithCustomPayloadTypeIdentifierAndContentBlockWithoutPayl
var parser = new WarcParser(recordFactory);
var path = $"{WarcParserTest.DirectoryForValidRecords}1.1{Path.DirectorySeparatorChar}misc{Path.DirectorySeparatorChar}response_gemini_wo_payload.warc";

var records = await parser.Parse(path).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path).ToListAsync();
var actualRecord = (ResponseRecord)records[0];

Assert.Equal(ExpectedRecordBlock, actualRecord.RecordBlock);
Expand All @@ -104,7 +104,7 @@ public async Task ParseWithCustomPayloadTypeIdentifierAndContentBlockWithPayload
var parser = new WarcParser(recordFactory);
var path = $"{WarcParserTest.DirectoryForValidRecords}1.1{Path.DirectorySeparatorChar}misc{Path.DirectorySeparatorChar}response_gemini_w_payload.warc";

var records = await parser.Parse(path).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path).ToListAsync();
var actualRecord = (ResponseRecord)records[0];

Assert.Equal(ExpectedRecordBlock, actualRecord.RecordBlock);
Expand Down
56 changes: 28 additions & 28 deletions tests/Toimik.WarcProtocol.Tests/WarcParserTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace Toimik.WarcProtocol.Tests;

using ICSharpCode.SharpZipLib.GZip;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ICSharpCode.SharpZipLib.GZip;
using Xunit;

public class WarcParserTest
Expand Down Expand Up @@ -42,7 +42,7 @@ public async Task ExceptionDueToLongerContentLengthButIsSuppressed()
var path = $"{DirectoryForInvalidRecords}short_content_block.warc";
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();

Assert.Empty(records);
var actualMessage = parseLog.Messages[0];
Expand All @@ -56,7 +56,7 @@ public async Task ExceptionDueToLongerContentLengthButIsUnsuppressed()

var path = $"{DirectoryForInvalidRecords}short_content_block.warc";

var ex = await Assert.ThrowsAsync<FormatException>(async () => await parser.Parse(path).ToListAsync().ConfigureAwait(false)).ConfigureAwait(false);
var ex = await Assert.ThrowsAsync<FormatException>(async () => await parser.Parse(path).ToListAsync());
Assert.Contains("Content block is", ex.Message);
}

Expand All @@ -67,7 +67,7 @@ public async Task ExceptionDueToMalformedHeaderThatIsSuppressed()
var path = $"{DirectoryForInvalidRecords}malformed_header.warc";
var parseLog = new CustomParseLog();

await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
await parser.Parse(path, parseLog).ToListAsync();

var expectedMessages = new List<string>
{
Expand Down Expand Up @@ -118,7 +118,7 @@ public async Task ExceptionDueToMalformedHeaderThatIsUnsuppressed()

var path = $"{DirectoryForInvalidRecords}malformed_header.warc";

await Assert.ThrowsAsync<FormatException>(async () => await parser.Parse(path).ToListAsync().ConfigureAwait(false)).ConfigureAwait(false);
await Assert.ThrowsAsync<FormatException>(async () => await parser.Parse(path).ToListAsync());
}

[Fact]
Expand All @@ -128,7 +128,7 @@ public async Task ExceptionDueToMissingMandatoryHeaderFieldButIsSuppressed()
var path = $"{DirectoryForInvalidRecords}missing_header_field.warc";
var parseLog = new CustomParseLog();

await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
await parser.Parse(path, parseLog).ToListAsync();

var expectedCounter = 4;
Assert.Equal(expectedCounter, parseLog.Messages.Count);
Expand All @@ -140,7 +140,7 @@ public async Task ExceptionDueToMissingMandatoryHeaderFieldButIsUnsuppressed()
var parser = new WarcParser();
var path = $"{DirectoryForInvalidRecords}missing_header_field.warc";

var exception = await Assert.ThrowsAsync<FormatException>(async () => await parser.Parse(path).ToListAsync().ConfigureAwait(false)).ConfigureAwait(false);
var exception = await Assert.ThrowsAsync<FormatException>(async () => await parser.Parse(path).ToListAsync());
Assert.Contains("One of the mandatory header fields is missing", exception.Message);
}

Expand All @@ -153,7 +153,7 @@ public async Task ExceptionDueToPrematureEndOfFileButIsSuppressed(string filenam
var path = $"{DirectoryForInvalidRecords}{filename}";
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();

Assert.Empty(records);
var actualMessage = parseLog.Messages[0];
Expand All @@ -169,7 +169,7 @@ public async Task ExceptionDueToPrematureEndOfFileButIsUnsuppressed(string filen

var path = $"{DirectoryForInvalidRecords}{filename}";

var ex = await Assert.ThrowsAsync<FormatException>(async () => await parser.Parse(path).ToListAsync().ConfigureAwait(false)).ConfigureAwait(false);
var ex = await Assert.ThrowsAsync<FormatException>(async () => await parser.Parse(path).ToListAsync());
Assert.Contains("Premature end of file", ex.Message);
}

Expand All @@ -189,7 +189,7 @@ public async Task IncorrectContentLengthThatIsUncompressed()
var records = parser.Parse(path, parseLog);

var index = 0;
await foreach (WarcProtocol.Record record in records.ConfigureAwait(false))
await foreach (WarcProtocol.Record record in records)
{
var expectedContent = expectedContents[index];
var actualContent = Encoding.UTF8.GetString(((ResourceRecord)record).RecordBlock!);
Expand Down Expand Up @@ -232,7 +232,7 @@ public async Task IndividualRecordThatIsCompressed(string filename)
var path = $"{DirectoryForValid1Point1Records}{filename}";
tempCompressedFile = CompressFile(path);

await TestUtils.TestFile(tempCompressedFile, recordCount: 1).ConfigureAwait(false);
await TestUtils.TestFile(tempCompressedFile, recordCount: 1);
}
finally
{
Expand Down Expand Up @@ -269,7 +269,7 @@ public async Task MergedRecordsThatAreIndividuallyCompressedAsOneFile(bool isCus
await TestUtils.TestFile(
path,
MergeFilenames.Count,
compressionStreamFactory).ConfigureAwait(false);
compressionStreamFactory);
}
finally
{
Expand All @@ -286,7 +286,7 @@ public async Task MergedRecordsThatAreUncompressedAsOneFile()
path = TestUtils.CreateTempFile(FileExtensionForUncompressed);
MergeUncompressedRecords(path);

await TestUtils.TestFile(path, MergeFilenames.Count).ConfigureAwait(false);
await TestUtils.TestFile(path, MergeFilenames.Count);
}
finally
{
Expand All @@ -313,7 +313,7 @@ public async Task MergedRecordsThatAreWhollyCompressedAsOneFile(bool isCustomCom
await TestUtils.TestFile(
tempCompressedFile,
MergeFilenames.Count,
compressionStreamFactory).ConfigureAwait(false);
compressionStreamFactory);
}
finally
{
Expand All @@ -328,7 +328,7 @@ public async Task MultilineHeaderValues()
var parser = new WarcParser();
var path = $"{DirectoryForInvalidRecords}multiline_header_values.warc";

var records = await parser.Parse(path).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path).ToListAsync();
var record = (ResourceRecord)records[0];

Assert.Equal("1.0", record.Version);
Expand All @@ -344,7 +344,7 @@ public async Task OffsetOverLimit()
var parser = new WarcParser();
var path = $"{DirectoryForInvalidRecords}incorrect_content_length.warc";

var exception = await Assert.ThrowsAsync<ArgumentException>(async () => await parser.Parse(path, byteOffset: 1000).ToListAsync().ConfigureAwait(false)).ConfigureAwait(false);
var exception = await Assert.ThrowsAsync<ArgumentException>(async () => await parser.Parse(path, byteOffset: 1000).ToListAsync());

Assert.Contains("Offset exceeds file size", exception.Message);
}
Expand All @@ -355,7 +355,7 @@ public async Task OffsetUnderLimit()
var parser = new WarcParser();
var path = $"{DirectoryForInvalidRecords}incorrect_content_length.warc";

var records = await parser.Parse(path, byteOffset: 697).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, byteOffset: 697).ToListAsync();
var record = (ResourceRecord)records[0];

Assert.Equal("1.1", record.Version);
Expand All @@ -380,7 +380,7 @@ public async Task RecordForContinuationThatIsUncompressed(string version, bool i
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (ContinuationRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down Expand Up @@ -436,7 +436,7 @@ public async Task RecordForConversionThatIsUncompressed(string version, bool isW
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (ConversionRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down Expand Up @@ -492,7 +492,7 @@ public async Task RecordForMetadataThatIsUncompressed(string version, bool isWit
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (MetadataRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down Expand Up @@ -547,7 +547,7 @@ public async Task RecordForRequestThatIsUncompressed(string version, bool isWith
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (RequestRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down Expand Up @@ -603,7 +603,7 @@ public async Task RecordForResourceThatIsUncompressed(string version, bool isWit
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (ResourceRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down Expand Up @@ -660,7 +660,7 @@ public async Task RecordForResponseThatIsUncompressed(string version, bool isWit
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (ResponseRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down Expand Up @@ -717,7 +717,7 @@ public async Task RecordForRevisitOfIdenticalThatIsUncompressed(string version,
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (RevisitRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down Expand Up @@ -759,8 +759,8 @@ public async Task RecordForRevisitOfIdenticalThatIsUncompressed(string version,
var expectedHeader = expectedRecord.GetHeader(fields);

// NOTE: Parsing warc files will preserve the value of Content-Type, if any. However,
// creating a record with a Content-Length of zero will cause a non-null Content-Type to
// be null. Thus, the Content-Type for this record is removed.
// creating a record with a Content-Length of zero will cause a non-null Content-Type to be
// null. Thus, the Content-Type for this record is removed.
fields.Remove(RevisitRecord.FieldForContentType);

var actualHeader = actualRecord.GetHeader(fields);
Expand All @@ -781,7 +781,7 @@ public async Task RecordForRevisitOfUnmodifiedThatIsUncompressed(string version,
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (RevisitRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down Expand Up @@ -837,7 +837,7 @@ public async Task RecordForWarcinfoThatIsUncompressed(bool isWithoutBlockDigest)
isWithoutBlockDigest);
var parseLog = new CustomParseLog();

var records = await parser.Parse(path, parseLog).ToListAsync().ConfigureAwait(false);
var records = await parser.Parse(path, parseLog).ToListAsync();
var actualRecord = (WarcinfoRecord)records[0];

var digestFactory = CreateDigestFactory(actualRecord.BlockDigest);
Expand Down

0 comments on commit b9e58a5

Please sign in to comment.