Skip to content
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

Generator implementation for V2 smoke tests for C2J files. #3578

Open
wants to merge 2 commits into
base: normj/v4-smoketests
Choose a base branch
from

Conversation

AlexDaines
Copy link
Contributor

Description

Implements the generator for smoke tests v2 format based on the new smoke-2.json schema. Key features:

  • Supports all configuration options from the smoke-2.json schema
  • Handles complex input types including arrays and nested objects
  • Generates both success and failure test cases
  • Includes proper test categorization
  • Manages special cases for Tags and Includes objects

Questions for review:

  1. Special case handling for Tags/Includes - should this be more generic?
  2. Configuration defaults - should we explicitly set schema defaults?
  3. Error handling - any additional checks needed beyond ErrorCode?
  4. Input validation - should we validate against operation parameters?
  5. Test categorization - any additional AWS-specific categories needed?

Motivation and Context

This implementation supports the new smoke tests format (smoke-2.json) which provides more configuration options and better structure for test cases. The generator creates test files that:

  • Allow per-test configuration
  • Support all endpoint configuration options
  • Handle complex input structures
  • Provide proper error handling and validation

Testing

  • Verified generation with ACM service model
  • Tested various scenarios including:
    • Success and failure cases
    • Complex input structures (arrays, nested objects)
    • Special cases (Tags, Includes)
    • Edge cases (null values, empty strings)
    • All configuration options
  • Generated tests compile successfully

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

}
}
#>
public async Task <#=testCase["id"]?.ToString() ?? "Test"#>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were there tests without an id field? Seems like a field that would be required.

}
else
{
var arrayValues = new List<string>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't remember in the SEP can there be arrays of more then just strings.

@@ -8,6 +8,7 @@
AddLicenseHeader();
#>
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm not reviewing the PR, but...) Is there a reason why you're using MSTest as the test framework?

The hand-written files we have right now use xUnit (meaning they can run in parallel) and using xUnit will allow you to test your PR without making any changes to our build system (as long as they're found by the projects in this folder: https://github.com/aws/aws-sdk-net/tree/v4-development/sdk/test/SmokeTests).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless you want to make a buildsystem change I'd probably listen to daniel here

@peterrsongg
Copy link
Contributor

the file isn't in this PR but shouldn't you remove this logic in GeneratorDriver.cs?

            if (this.Configuration.ServiceModel.HasSmokeTestsV2 && 
                (this.Configuration.ServiceId == "API Gateway" || this.Configuration.ServiceId == "ACM") )
            {
                ExecuteIntegrationTestGenerator(new SmokeTestsV2(), "SmokeTestsV2.cs");
            }

I'm assuming that was just put there for testing purposes, but we should be generating smoke tests for every service

@peterrsongg
Copy link
Contributor

peterrsongg commented Jan 8, 2025

I tried running the generator and it seems like this needs to be changed as well

                ExecuteIntegrationTestGenerator(new SmokeTestsV2(), "SmokeTestsV2.cs");

with this logic, each file will be SmokeTestsV2.cs and one will overwrite the other. You should~~~~probably do something similar to the other generators and do something like

ExecuteIntegrationTestGenerator(new SmokeTestsV2(), serviceName + "SmokeTestsV2.cs");

Either that or something weird is going on with the generator, but I don't see the files in there for some reason

hmm so actually it is generating it, but then it is being removed and the output of the generator is showing

**** Warning: Removing orphaned generated test code SmokeTestsV2.cs

and that's why it wasn't showing up for me.

@peterrsongg peterrsongg requested review from peterrsongg and removed request for gcbeattyAWS and boblodgett January 8, 2025 01:48
@peterrsongg
Copy link
Contributor

peterrsongg commented Jan 8, 2025

^^ looking into the problem I mentioned above a bit more, it seems like it thinks these generated integ tests are orphaned files because they are not a part of the generatedTestFiles that get populated here
https://github.com/aws/aws-sdk-net/blob/main/generator/ServiceClientGenerator/Program.cs#L64-L79

since it is not part of that list, when it is passed into GeneratorDriver.RemoveOrphanedShapesAndServices it gets removed. This is probably the first instance of a generated integ tests so you should add these generated integ tests to the list so it isn't removed.

The removing of the orphaned code should definitely be fixed, since it makes it kind of hard to review without knowing what every smoke test file looks like.

var response = await serviceClient.<#=modeledOperation.Name#>Async(request);
<#
var input = testCase["input"] as JsonData;
if (input != null && input.IsObject)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we need to check input.IsObject? if input != null, then we are guaranteed to be given a json object wityh the input so I think we can remove the IsObject check.

foreach (string jsonKey in input.PropertyNames)
{
var propertyName = FindPropertyName(modeledOperation, jsonKey);
var value = input[jsonKey];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since the name is propertyName, you could make it consistent and say propertyValue for the value. fine with me if u dont want to change though

<#
foreach (JsonData tag in value)
{
if (tag != null && tag.IsObject && tag["Key"] != null && tag["Value"] != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here about IsObject. Is it required?

return (bool)useAccountIdRouting;
}

public string[] GetSigV4aRegionSet(JsonData testCase)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just make the return type List<string>, which would remove the extra regions.ToArray() call at the end and instead just return regions.

if (IsSuccessExpected(testCase))
{
#>
var response = await serviceClient.<#=modeledOperation.Name#>Async(request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add .ConfigureAwait(false) at the end of this async call. We should always be adding that at the end of async calls, unless you really know what you're doing. See https://devblogs.microsoft.com/dotnet/configureawait-faq/#why-would-i-want-to-use-configureawait(false) for why we should use configureAwait(false)

#>
try
{
var response = await serviceClient.<#=modeledOperation.Name#>Async(request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

@@ -8,6 +8,7 @@
AddLicenseHeader();
#>
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless you want to make a buildsystem change I'd probably listen to daniel here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants