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

[Synapse] Rework and extend unit tests #18010

Merged
merged 10 commits into from
Jan 21, 2021

Conversation

chamons
Copy link
Contributor

@chamons chamons commented Jan 15, 2021

This is the first in a set of PRs intended to complete a basic level of test coverage on Synapse. This one in particular is more extension, and less additive, as it refactors and restructures the existing tests.

Some notes:

  • I've removed the shared testing base class, and moved some test helpers into static methods that declare the needed resources instead of digging into the base class's public variables. I also explicitly instance the test class in each test.
    • I prefer less magic and more explicit behavior as a rule. I find this easier to maintain.
    • I also updated test and sample namespaces to match the guidance from the template Foo.Bar.Tests or Foo.Bar.Samples
  • A few new tests are included, just to prevent code coverage regressions. Some of them are [Ignored] due to current limitations in the test-resources.json instance, or issues with the service/SDK that I'm looking at.
  • I am aware that some of the tests I fixed up in the refactor don't assert much, or could be improved further. As I noted above, additional test work will continue after this.
  • I added a bunch of "stub" test classes just to fill out the set of test files, and to make it explicit what isn't being tested yet.
  • This PR is best gone by commit by commit. The "Test recordings" PR can be skipped.

Copy link
Member

@jsquire jsquire left a comment

Choose a reason for hiding this comment

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

LGTM, though you may want to get another pair of eyes more familiar with the recorded test infrastructure to take a peek.

));
}

[Ignore("This test case cannot be automated due to the inability to configure infrastructure to test against.")]
Copy link
Member

Choose a reason for hiding this comment

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

There's a test category "Manually" that seems to be the recommended approach for these types. Tests with that category are not run automatically by the pipelines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe most of these could be automated, I don't want to give up yet. Filing an issue and using it to track.

Copy link
Contributor Author

Choose a reason for hiding this comment

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


DataFlowCreateOrUpdateDataFlowOperation createOperation = await DataFlowClient.StartCreateOrUpdateDataFlowAsync(dataFlowName, new DataFlowResource(new DataFlow()));
await createOperation.WaitForCompletionAsync();
// Non-disposable as we'll be deleting it ourselves
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what this comments means. I think you're saying "This resource is disposable but we're not going to dispose it so that we can control deletion." - am I close?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was "we're getting the raw resource and not using the Disposable for a reason here. If that wasn't clear, maybe I should just nuke the comment.

[Test]
public async Task TestGetLinkedService()
{
await foreach (var expectedLinkedService in LinkedServiceClient.GetLinkedServicesByWorkspaceAsync())
LinkedServiceClient client = CreateClient ();
Copy link
Member

Choose a reason for hiding this comment

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

nit: Extra space before parenthesis.

/// <typeparam name="T">The item type.</typeparam>
/// <param name="items">The sequence of items.</param>
/// <returns>A list of all the items in the sequence.</returns>
public static async Task<IList<T>> ToListAsync<T>(this IAsyncEnumerable<T> items)
Copy link
Member

Choose a reason for hiding this comment

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

I think there may be something in the test framework that does this....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found a few copies, but none in a common location:

PS C:\Users\chhamo\Programming\azure-sdk-for-net\sdk> git grep ToListAsync | Select-String Task

batch/Microsoft.Azure.Batch.FileStaging/tests/FileStagingIntegrationTests.cs:                List<CloudTask> tasksFromService = await
jobOperations.ListTasks(jobId).ToListAsync().ConfigureAwait(false);
batch/Microsoft.Azure.Batch/src/PagedEnumerableExtensions.cs:        public static async Task<List<T>> ToListAsync<T>(this IPagedEnumerable<T> source,
CancellationToken cancellationToken = default(CancellationToken))
batch/Microsoft.Azure.Batch/tests/IntegrationTests/AddTaskCollectionIntegrationTests.cs:                List<CloudTask> tasksFromService = await
jobOperations.ListTasks(jobId).ToListAsync().ConfigureAwait(false);
batch/Microsoft.Azure.Batch/tests/UnitTests/PagedCollectionUnitTests.cs:        public async Task IfSequenceIsNull_ThenToListAsyncThrowsArgumentNullException()
batch/Microsoft.Azure.Batch/tests/UnitTests/PagedCollectionUnitTests.cs:        public async Task ToListAsyncCollectsAllElementsOfSequence()
batch/Microsoft.Azure.Batch/tests/UnitTests/PagedCollectionUnitTests.cs:        public async Task ToListAsyncCorrectlyHandlesEmptyCollections()
batch/Microsoft.Azure.Batch/tests/UnitTests/PagedCollectionUnitTests.cs:        public async Task ToListAsyncSupportsCancellation()
search/Azure.Search.Documents/tests/Utilities/TestExtensions.cs:        public static async Task<List<T>> ToListAsync<T>(this AsyncPageable<T> pageable)
storage/Azure.Storage.Common/tests/Shared/TestExtensions.cs:        public static async Task<IList<T>> ToListAsync<T>(this IAsyncEnumerable<T> items)
synapse/Azure.Analytics.Synapse.Shared/tests/SynapseTestExtensions.cs:        public static async Task<IList<T>> ToListAsync<T>(this IAsyncEnumerable<T> items)

ValidateSparkBatchJob(expectedSparkJob, actualSparkJob);
}
catch (Azure.RequestFailedException)
{
}
}
}

internal void ValidateSparkBatchJob(SparkBatchJob expectedSparkJob, SparkBatchJob actualSparkJob)
Copy link
Member

Choose a reason for hiding this comment

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

I keep reading these as SparkleBatchJob

string name = test.Recording.GenerateName("dontnetbatch");
string file = string.Format("abfss://{0}@{1}.dfs.core.windows.net/samples/java/wordcount/wordcount.jar", test.TestEnvironment.StorageFileSystemName, test.TestEnvironment.StorageAccountName);
string name = recording.GenerateName("dontnetbatch");
string file = string.Format("abfss://{0}@{1}.dfs.core.windows.net/samples/java/wordcount/wordcount.jar", testEnvironment.StorageFileSystemName, testEnvironment.StorageAccountName);
Copy link
Member

Choose a reason for hiding this comment

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

Does it matter that these are referring to java. Is this URI stable across environments/platforms/clouds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests require the uploaded sample from the team copied onto the shared storage, which can be either java, python, or dotnet.

This code in question was from the client team, and defaulted to java. I'm planning on improving this in a future PR.

@chamons
Copy link
Contributor Author

chamons commented Jan 20, 2021

Changing the ID generation invalidated all of the recordings. Fixing.

@chamons chamons merged commit ecc44d6 into Azure:master Jan 21, 2021
@chamons chamons deleted the synapse_test_coverage_smash branch January 21, 2021 15:33
minnieliu pushed a commit to minnieliu/azure-sdk-for-net that referenced this pull request Jan 23, 2021
This is the first in a set of PRs intended to complete a basic level of test coverage on Synapse. This one in particular is more extension, and less additive, as it refactors and restructures the existing tests. 

Some notes:
- I've removed the shared testing base class, and moved some test helpers into static methods that declare the needed resources instead of digging into the base class's public variables. I also explicitly instance the test class in each test.
   - I prefer less magic and more explicit behavior as a rule. I find this easier to maintain.
   - I also updated test and sample namespaces to match the guidance from the template Foo.Bar.Tests or Foo.Bar.Samples
- A few new tests are included, just to prevent code coverage regressions. Some of them are [Ignored] due to current limitations in the test-resources.json instance, or issues with the service/SDK that I'm looking at.
- I am aware that some of the tests I fixed up in the refactor don't assert much, or could be improved further. As I noted above, additional test work will continue after this.
- I added a bunch of "stub" test classes just to fill out the set of test files, and to make it explicit what isn't being tested yet.
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.

3 participants