Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,27 @@ public static string GetTxtItinerary(string fileName)
public static string[] GetFileLines(string fileName)
{
var path = GetFile(fileName);
return File.ReadAllLines(path);
return ReadAllLinesShared(path);
}

// Reads all lines from a file while allowing other readers/writers to keep the
// file open concurrently. Test classes run in parallel and multiple theories read
// the same shared TestData files, which can otherwise race and throw an IOException
// ("The process cannot access the file because it is being used by another process")
// on Windows. Opening with FileShare.ReadWrite makes the shared reads deterministic.
public static string[] ReadAllLinesShared(string path)
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var reader = new StreamReader(stream);

var lines = new List<string>();
string? line;
while ((line = reader.ReadLine()) is not null)
{
lines.Add(line);
}

return lines.ToArray();
}

public static IEnumerable<object[]> JsonlItineraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Process_FromJsonlFile_ProducesValidJsonMatchingFinalLine(string file

// Arrange
var chunker = new JsonStreamChunker();
var lines = File.ReadAllLines(filePath);
var lines = DataStreamsHelper.ReadAllLinesShared(filePath);

// Act
var chunks = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Roundtrip_FromJsonlFile_DeserializerProducesEquivalentResult(string
_ = fileName; // We are not using the parameter here

// Arrange
var lines = File.ReadAllLines(filePath);
var lines = DataStreamsHelper.ReadAllLinesShared(filePath);
var finalLine = lines[^1];

// Act - pass each line through chunker and deserializer
Expand Down Expand Up @@ -48,7 +48,7 @@ public void Roundtrip_FromJsonlFile_EachLineDeserializesProgressively(string fil
_ = fileName; // We are not using the parameter here

// This test validates that each intermediate line produces a valid partial object
var lines = File.ReadAllLines(filePath);
var lines = DataStreamsHelper.ReadAllLinesShared(filePath);

var models = ProcessLines<Itinerary>(lines);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void ProcessChunk_TxtFile_DeserializesProgressively(string fileName, stri
{
_ = fileName; // Used for test display name
var deserializer = new StreamingJsonDeserializer<Itinerary>(DeserializationOptions);
var chunks = File.ReadAllLines(filePath);
var chunks = DataStreamsHelper.ReadAllLinesShared(filePath);

Itinerary? lastItinerary = null;

Expand All @@ -41,7 +41,7 @@ public void ProcessChunk_TxtFile_FinalResultMatchesDirectDeserialization(string
{
_ = fileName; // Used for test display name
var deserializer = new StreamingJsonDeserializer<Itinerary>(DeserializationOptions);
var chunks = File.ReadAllLines(filePath);
var chunks = DataStreamsHelper.ReadAllLinesShared(filePath);

Itinerary? finalItinerary = null;

Expand All @@ -65,7 +65,7 @@ public void ProcessChunk_TxtFile_FinalResultMatchesDirectDeserialization(string
public void ProcessChunk_TxtFile_ShouldProgressDaysArray(string fileName, string filePath)
{
var deserializer = new StreamingJsonDeserializer<Itinerary>(DeserializationOptions);
var chunks = File.ReadAllLines(filePath);
var chunks = DataStreamsHelper.ReadAllLinesShared(filePath);

var daysProgression = new List<(int ChunkNumber, int? DaysCount, int? ActivitiesInFirstDay)>();

Expand Down Expand Up @@ -98,7 +98,7 @@ public void ProcessChunk_TxtFile_ShouldProgressDaysArray(string fileName, string
public void ProcessChunk_TxtFile_ShouldProgressTitleField(string fileName, string filePath)
{
var deserializer = new StreamingJsonDeserializer<Itinerary>(DeserializationOptions);
var chunks = File.ReadAllLines(filePath);
var chunks = DataStreamsHelper.ReadAllLinesShared(filePath);

var titleProgression = new List<string?>();

Expand Down Expand Up @@ -129,7 +129,7 @@ public void ProcessChunk_TxtFile_EachChunkProducesNonEmptyObject(string fileName
{
_ = fileName; // Used for test display name
var deserializer = new StreamingJsonDeserializer<Itinerary>(DeserializationOptions);
var chunks = File.ReadAllLines(filePath);
var chunks = DataStreamsHelper.ReadAllLinesShared(filePath);

foreach (var chunk in chunks)
{
Expand All @@ -152,7 +152,7 @@ public void ProcessChunk_TxtFile_UpdateRate(string fileName, string filePath)
// partial property values, or unchanged content - 70% is a reasonable threshold.

var deserializer = new StreamingJsonDeserializer<Itinerary>(DeserializationOptions);
var chunks = File.ReadAllLines(filePath);
var chunks = DataStreamsHelper.ReadAllLinesShared(filePath);

string? previousJson = null;
int totalChunks = 0;
Expand Down
Loading