-
Notifications
You must be signed in to change notification settings - Fork 4
Added RETRY-UNTIL-TEST-PASS directive #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Initialize counters for different retry scenarios | ||
| tp.SetVariable("CarAvailabilityCheckCount", 0); | ||
| tp.SetVariable("UnavailableCarCheckCount", 0); | ||
| tp.SetVariable("CarCreationCheckCount", 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| ### Scenario 1: Check Car Availability (passes after 3 attempts) | ||
| ## RETRY-STRATEGY: Custom retry | ||
| ## RETRY-MAX-ATTEMPTS: 5 | ||
| ## RETRY-UNTIL-TEST-PASS: Car should be available | ||
|
|
||
| # @name CheckCarAvailabilityRequest | ||
| GET {{ApiBaseUrl}}{{ApiCarsSection}}/1 | ||
|
|
||
| ### | ||
|
|
||
| ### Scenario 2: Check Unavailable Car (never passes - exceeds max attempts) | ||
| ## RETRY-STRATEGY: Custom retry | ||
| ## RETRY-MAX-ATTEMPTS: 3 | ||
| ## RETRY-UNTIL-TEST-PASS: Car with special features should exist | ||
|
|
||
| # @name CheckUnavailableCarRequest | ||
| GET {{ApiBaseUrl}}{{ApiCarsSection}}/999 | ||
|
|
||
| ### | ||
|
|
||
| ### Scenario 3: Verify Car Creation (combined RETRY-UNTIL-STATUS + RETRY-UNTIL-TEST-PASS) | ||
| ## RETRY-STRATEGY: Custom retry | ||
| ## RETRY-MAX-ATTEMPTS: 4 | ||
| ## RETRY-MAX-DELAY: 00:00:02 | ||
| ## RETRY-UNTIL-STATUS: [200, 201] | ||
| ## RETRY-UNTIL-TEST-PASS: Newly created car should have correct brand | ||
|
|
||
| # @name VerifyCarCreationRequest | ||
| GET {{ApiBaseUrl}}{{ApiCarsSection}}/1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Test 1: Car becomes available after 3 attempts | ||
| tp.Test("Car should be available", () => | ||
| { | ||
| var attempt = tp.GetVariable<int>("CarAvailabilityCheckCount"); | ||
| attempt++; | ||
| tp.SetVariable("CarAvailabilityCheckCount", attempt); | ||
|
|
||
| var response = tp.Response; | ||
| var statusCode = response.StatusCode(); | ||
|
|
||
| if (attempt >= 3) | ||
| { | ||
| Equal(200, statusCode); | ||
| } | ||
| else | ||
| { | ||
| Fail($"Car not available yet (attempt {attempt})"); | ||
| } | ||
| }); | ||
|
|
||
| // Test 2: Car never becomes available (will fail after max attempts) | ||
| await tp.Test("Car with special features should exist", async () => | ||
| { | ||
| var attempt = tp.GetVariable<int>("UnavailableCarCheckCount"); | ||
| attempt++; | ||
| tp.SetVariable("UnavailableCarCheckCount", attempt); | ||
|
|
||
| var response = tp.Response; | ||
| var statusCode = response.StatusCode(); | ||
|
|
||
| // This will always fail - demonstrating max attempts behavior | ||
| Equal(200, statusCode); | ||
|
|
||
| dynamic carData = await response.GetBodyAsExpandoAsync(); | ||
| Equal("SpecialFeatures", carData.Brand); | ||
| }); | ||
|
|
||
| // Test 3: Combined scenario - verify newly created car has correct brand | ||
| await tp.Test("Newly created car should have correct brand", async () => | ||
| { | ||
| var attempt = tp.GetVariable<int>("CarCreationCheckCount"); | ||
| attempt++; | ||
| tp.SetVariable("CarCreationCheckCount", attempt); | ||
|
|
||
| var response = tp.Response; | ||
| var statusCode = response.StatusCode(); | ||
|
|
||
| if (attempt >= 2 && (statusCode == 200 || statusCode == 201)) | ||
| { | ||
| dynamic carData = await response.GetBodyAsExpandoAsync(); | ||
| Equal(200, statusCode); | ||
| } | ||
| else | ||
| { | ||
| Fail($"Car not ready yet (attempt {attempt})"); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/TeaPie/Http/Retrying/RetryUntilTestPassDirectiveLineParser.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using System.Text.RegularExpressions; | ||
| using TeaPie.Http.Parsing; | ||
|
|
||
| namespace TeaPie.Http.Retrying; | ||
|
|
||
| internal partial class RetryUntilTestPassDirectiveLineParser : ILineParser | ||
| { | ||
| public bool CanParse(string line, HttpParsingContext context) | ||
| => Regex.IsMatch(line, RetryingDirectives.RetryUntilTestPassDirectivePattern); | ||
|
|
||
| public void Parse(string line, HttpParsingContext context) | ||
| { | ||
| var match = Regex.Match(line, RetryingDirectives.RetryUntilTestPassDirectivePattern); | ||
|
pavolbetak marked this conversation as resolved.
|
||
| if (match.Success) | ||
| { | ||
| var testName = match.Groups[RetryingDirectives.RetryUntilTestPassDirectiveParameterName].Value; | ||
| context.RetryUntilTestPassTestName = testName.Trim(); | ||
| } | ||
| else | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"Unable to parse '{RetryingDirectives.RetryUntilTestPassDirectiveFullName}' " + | ||
| "if directive doesn't match the structure."); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using TeaPie.Pipelines; | ||
| using TeaPie.Reporting; | ||
| using TeaPie.TestCases; | ||
| using TeaPie.Testing; | ||
|
|
||
| namespace TeaPie.Scripts; | ||
|
|
||
| internal class RunScriptTestsStep( | ||
| ITestCaseExecutionContextAccessor accessor, | ||
| ITestResultsSummaryReporter resultsSummaryReporter, | ||
| ITester testExecutor) : IPipelineStep | ||
| { | ||
| private readonly ITestCaseExecutionContextAccessor _accessor = accessor; | ||
| private readonly ITestResultsSummaryReporter _resultsSummaryReporter = resultsSummaryReporter; | ||
| private readonly ITester _testExecutor = testExecutor; | ||
|
|
||
| public async Task Execute(ApplicationContext context, CancellationToken cancellationToken = default) | ||
| { | ||
| _resultsSummaryReporter.Initialize(); | ||
|
|
||
| var testCaseExecutionContext = _accessor.Context!; | ||
| foreach (var test in testCaseExecutionContext.GetTests()) | ||
| { | ||
| await _testExecutor.ExecuteOrSkipTest(test, testCaseExecutionContext.TestCase); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naozaj si toto chcel zmazat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem je, ze ked chces precitat testy, tak musis executnut ten subor a vzhladom na toto, ze toto je mimo tych tp.Test, tak sa to hned odpali a premaze variables (toto sa deje pri nacitami testov, nie spusteny) a potom ked dojde na spustenie, tak niektore tie variables chybaju a padne to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bude treba odstranit aj referenciu #load "$teapie/ClearVariables.csx"