Skip to content

Commit

Permalink
Moved to UUID generation only and removed the ID rewriting code durin…
Browse files Browse the repository at this point in the history
…g Feature start.
  • Loading branch information
clrudolphi committed Feb 12, 2025
1 parent 71aac1b commit 15f0230
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 352 deletions.
3 changes: 2 additions & 1 deletion Reqnroll.Generator/Generation/UnitTestFeatureGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using Gherkin.CucumberMessages;
using Reqnroll.Configuration;
using Reqnroll.CucumberMessages.Configuration;
using Reqnroll.CucumberMessages.RuntimeSupport;
Expand Down Expand Up @@ -261,7 +262,7 @@ private void DeclareFeatureMessagesFactoryMembers(TestClassGenerationContext gen

try
{
var messageConverter = new CucumberMessagesConverter(new SeedableIncrementingIdGenerator(0));
var messageConverter = new CucumberMessagesConverter(new GuidIdGenerator());
var featureSource = Reqnroll.CucumberMessages.PayloadProcessing.Cucumber.CucumberMessageTransformer.ToSource(messageConverter.ConvertToCucumberMessagesSource(generationContext.Document));
var featureGherkinDocument = messageConverter.ConvertToCucumberMessagesGherkinDocument(generationContext.Document);
var featurePickles = messageConverter.ConvertToCucumberMessagesPickles(featureGherkinDocument);
Expand Down
11 changes: 1 addition & 10 deletions Reqnroll/CucumberMessages/ExecutionTracking/FeatureTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public IEnumerable<Envelope> RuntimeGeneratedMessages
{
get
{
return testCaseTrackersById.Values.SelectMany(scenario => scenario.RuntimeGeneratedMessages);
return testCaseTrackersById.Values.OrderBy(tc => tc.TestCaseStartedTimeStamp).SelectMany(scenario => scenario.RuntimeGeneratedMessages);
}
}

Expand All @@ -86,15 +86,6 @@ private IEnumerable<Envelope> GenerateStaticMessages(FeatureStartedEvent feature

var pickles = featureStartedEvent.FeatureContext.FeatureInfo.FeatureCucumberMessages.Pickles().ToList();

// When first created by the UnitTestFeatureGenerator, the IDs given to GherkinDocument and Pickles were based on IDs starting at '1'.
// By the time a Feature starts at test execution time, other messages have already been generated and written (eg, the StepDefinitions based on the StepBindingRegistry)
// Therefore, we have to rewrite the GherkinDocument and Pickles to give them IDs that fit after the IDs that have already been generated.

var idReWriter = new CucumberMessages.RuntimeSupport.IdReWriter();
idReWriter.ReWriteIds(gd, pickles, IDGenerator, out var reWrittenGherkinDocument, out var reWrittenPickles);
gd = reWrittenGherkinDocument;
pickles = reWrittenPickles.ToList();

for (int i = 0; i < pickles.Count; i++)
{
PickleIds.Add(i.ToString(), pickles[i].Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal TestCaseTracker(FeatureTracker featureTracker, string pickleId)
IDGenerator = featureTracker.IDGenerator;
StepDefinitionsByPattern = featureTracker.StepDefinitionsByPattern;
AttemptCount = -1;
TestCaseStartedTimeStamp = DateTime.Now;
}

// Feature FeatureName and Pickle ID make up a unique identifier for tracking execution of Test Cases
Expand All @@ -36,7 +37,7 @@ internal TestCaseTracker(FeatureTracker featureTracker, string pickleId)
internal string PickleId { get; } = string.Empty;
internal string TestCaseId { get; private set; }
internal int AttemptCount { get; private set; }

public object TestCaseStartedTimeStamp { get; }
internal bool Enabled { get; } //This will be false if the feature could not be pickled
internal bool Finished { get; private set; }
internal ScenarioExecutionStatus ScenarioExecutionStatus { get { return ExecutionHistory.Last().ScenarioExecutionStatus; } }
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void PublisherStartup(object sender, RuntimePluginBeforeTestRunEventArgs
return;
}

SharedIDGenerator = new SeedableIncrementingIdGenerator(0);
SharedIDGenerator = new GuidIdGenerator();
_testRunStartedId = SharedIDGenerator.GetNewId();

Task.Run(async () =>
Expand Down
28 changes: 0 additions & 28 deletions Reqnroll/CucumberMessages/RuntimeSupport/IdReWriter.cs

This file was deleted.

Loading

0 comments on commit 15f0230

Please sign in to comment.