-
Notifications
You must be signed in to change notification settings - Fork 746
fix(toolkit): handle isCn when region is not initialized to fix extension activation failure #7599
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
Changes from 4 commits
9b4909b
fda32cc
ded7bf2
7bb6859
a3dfeb9
b9b59df
dbbe722
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { AWSError } from 'aws-sdk' | |
| import * as sinon from 'sinon' | ||
| import { DefaultEc2MetadataClient } from '../../shared/clients/ec2MetadataClient' | ||
| import * as vscode from 'vscode' | ||
| import { UserActivity, getComputeRegion, initializeComputeRegion } from '../../shared/extensionUtilities' | ||
| import { UserActivity, getComputeRegion, initializeComputeRegion, isCn } from '../../shared/extensionUtilities' | ||
| import { isDifferentVersion, setMostRecentVersion } from '../../shared/extensionUtilities' | ||
| import { InstanceIdentity } from '../../shared/clients/ec2MetadataClient' | ||
| import { extensionVersion } from '../../shared/vscode/env' | ||
|
|
@@ -135,6 +135,65 @@ describe('initializeComputeRegion, getComputeRegion', async function () { | |
| }) | ||
| }) | ||
|
|
||
| describe('isCn', function () { | ||
| let sandbox: sinon.SinonSandbox | ||
| const metadataService = new DefaultEc2MetadataClient() | ||
|
|
||
| beforeEach(function () { | ||
| sandbox = sinon.createSandbox() | ||
| }) | ||
|
|
||
| afterEach(function () { | ||
| sandbox.restore() | ||
| }) | ||
|
|
||
| it('returns false when compute region is not initialized', async function () { | ||
| // Reset the compute region to undefined first | ||
| const utils = require('../../shared/extensionUtilities') | ||
| Object.defineProperty(utils, 'computeRegion', { | ||
| value: undefined, | ||
| configurable: true, | ||
| }) | ||
|
|
||
| const result = isCn() | ||
|
|
||
| assert.strictEqual(result, false, 'isCn() should return false when compute region is not initialized') | ||
| }) | ||
|
|
||
| it('returns true for CN regions', async function () { | ||
| sandbox.stub(metadataService, 'getInstanceIdentity').resolves({ region: 'cn-north-1' }) | ||
| await initializeComputeRegion(metadataService, false, true) | ||
|
|
||
| const result = isCn() | ||
|
|
||
| assert.strictEqual(result, true, 'isCn() should return true for China regions') | ||
| }) | ||
|
|
||
| it('returns false for non-CN regions', async function () { | ||
| sandbox.stub(metadataService, 'getInstanceIdentity').resolves({ region: 'us-east-1' }) | ||
| await initializeComputeRegion(metadataService, false, true) | ||
|
|
||
| const result = isCn() | ||
|
|
||
| assert.strictEqual(result, false, 'isCn() should return false for non-China regions') | ||
| }) | ||
|
|
||
| it('returns false when an error occurs', async function () { | ||
| const utils = require('../../shared/extensionUtilities') | ||
|
|
||
| // Restore original getComputeRegion if it was stubbed | ||
| if (utils.getComputeRegion.restore) { | ||
| utils.getComputeRegion.restore() | ||
| } | ||
|
||
|
|
||
| sandbox.stub(utils, 'getComputeRegion').throws(new Error('Test error')) | ||
|
|
||
| const result = isCn() | ||
|
|
||
| assert.strictEqual(result, false, 'isCn() should return false when an error occurs') | ||
| }) | ||
| }) | ||
|
|
||
| describe('UserActivity', function () { | ||
| let count: number | ||
| let sandbox: sinon.SinonSandbox | ||
|
|
||
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.
Should we instead be throwing the error here? We already handle the known case above by returning false when the region is uninitialized, but this can catch other errors that I'm not sure we should assume returning false for.
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.
Good point, the case that throws error is handled already, and i didnt find any error cases that could result from the
getComputeRegionmethod, hence it looks safe to not throw error back