test(cloud): add projectId, serviceEmail cloud tests#214
test(cloud): add projectId, serviceEmail cloud tests#214brianquinlan wants to merge 10 commits intogoogleapis:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces end-to-end tests for the google_cloud package, including a dart_test.yaml configuration file and the test implementation in e2e_test.dart. The tests cover project ID retrieval, service account information, logging, and error handling. My review identified a potential resource leak in the test code where an HttpClient instance is not being closed after use, and I've provided a suggestion to fix it.
| final client = HttpClient(); | ||
| final req = await client.getUrl(gceMetadataUrl('')); | ||
| final res = await req.close(); | ||
| await res.drain<void>(); | ||
| return Response.ok('Metadata OK'); |
There was a problem hiding this comment.
The HttpClient instance created here is not closed, which can lead to resource leaks. You should ensure client.close() is called to properly release system resources. Using a try...finally block is a good pattern to ensure the client is closed even if errors occur.
final client = HttpClient();
try {
final req = await client.getUrl(gceMetadataUrl(''));
final res = await req.close();
await res.drain<void>();
return Response.ok('Metadata OK');
} finally {
client.close();
}There was a problem hiding this comment.
Code Review
This pull request introduces end-to-end tests for the google_cloud package, including a new dart_test.yaml configuration file. The tests validate key functionalities such as project ID retrieval, service account access, logging, and metadata server connectivity. While the additions are valuable, I've identified a potential resource leak in the test server implementation where an HttpClient is not properly closed. I've provided a specific suggestion to address this. For future contributions, it would be helpful to include a more descriptive pull request title and body to provide better context for reviewers.
| try { | ||
| final client = HttpClient(); | ||
| final req = await client.getUrl(gceMetadataUrl('')); | ||
| final res = await req.close(); | ||
| await res.drain<void>(); | ||
| return Response.ok('Metadata OK'); | ||
| } catch (e) { | ||
| return Response.internalServerError( | ||
| body: 'Metadata failed: $e', | ||
| ); | ||
| } |
There was a problem hiding this comment.
The HttpClient instance created here is not being closed, which can lead to resource leaks. An HttpClient should always be closed after use to release system resources. The recommended way to ensure this is to use a try...finally block, calling client.close() in the finally part.
final client = HttpClient();
try {
final req = await client.getUrl(gceMetadataUrl(''));
final res = await req.close();
await res.drain<void>();
return Response.ok('Metadata OK');
} catch (e) {
return Response.internalServerError(
body: 'Metadata failed: $e',
);
} finally {
client.close();
}
Adds integration tests (run on Google Cloud Build) for:
computeProjectIdserviceAccountEmailFromMetadataServer