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

Snow-1016470: increase code coverage #2011

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sfc-gh-ext-simba-jf
Copy link
Collaborator

Overview

SNOW-1016470

Pre-review self checklist

  • PR branch is updated with all the changes from master branch
  • The code is correctly formatted (run mvn -P check-style validate)
  • New public API is not unnecessary exposed (run mvn verify and inspect target/japicmp/japicmp.html)
  • The pull request name is prefixed with SNOW-XXXX:
  • Code is in compliance with internal logging requirements

External contributors - please answer these questions before submitting a pull request. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Issue: #NNNN

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency or upgrading an existing one
    • I am adding new public/protected component not marked with @SnowflakeJdbcInternalApi (note that public/protected methods/fields in classes marked with this annotation are already internal)
  3. Please describe how your code solves the related issue.

    Adding tests and refactoring to increase code coverage

injectedException = th;
}

public static boolean isInjectedExceptionEnabled() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be public

@@ -198,6 +200,11 @@ public StorageObjectSummaryCollection listObjects(String remoteStorageLocation,
logger.debug(
"Listing objects in the bucket {} with prefix {}", remoteStorageLocation, prefix);
Page<Blob> blobs = this.gcsClient.list(remoteStorageLocation, BlobListOption.prefix(prefix));
// Normal flow will never hit here. This is only for testing purposes
if (isInjectedExceptionEnabled()
&& SnowflakeGCSClient.injectedException instanceof StorageProviderException) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see why this instanceof is needed. If we inject an exception, then we shouldn't check it's type, just throw it. If you want to have a guarantee of it's type, just make the injected exception of this type instead of throwable

public void testDiagnosticCheckFailsWithNoAllowlistFileProvided() throws SQLException {
Properties props = new Properties();
props.put("ENABLE_DIAGNOSTICS", true);
try (Connection con = getConnection(props)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use assertThrows instead

Properties props = new Properties();
props.put("ENABLE_DIAGNOSTICS", true);
props.put("DIAGNOSTICS_ALLOWLIST_FILE", "/some/path/allowlist.json");
try (Connection con = getConnection(props)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, assetThrows

statement.execute("DROP STAGE if exists testStage");
}
}
SnowflakeGCSClient.setInjectedException(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be in a finally block. If the DROP STAGE fails for whatever reason, this would not be called.

@@ -1489,55 +1489,6 @@ public void testNoSpaceLeftOnDeviceException() throws SQLException {
}
}

@Test
@Disabled // TODO: ignored until SNOW-1616480 is resolved
public void testUploadWithGCSPresignedUrlWithoutConnection() throws Throwable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove this test?

// Normal flow will never hit here. This is only for testing purposes
if (isInjectedExceptionEnabled()
&& SnowflakeGCSClient.injectedException instanceof StorageProviderException) {
throw (StorageProviderException) SnowflakeGCSClient.injectedException;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This exception should be a StorageException to accurately mimic a failure. See the documentation for the list(...) method.

@@ -101,6 +101,8 @@ public class SnowflakeGCSClient implements SnowflakeStorageClient {

private static final SFLogger logger = SFLoggerFactory.getLogger(SnowflakeGCSClient.class);

private static Throwable injectedException = null; // for testing purpose
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you consider using mocks instead for this test?

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.

2 participants