File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import {
2929 testSshConnection ,
3030} from '../../shared/extensions/ssh'
3131import { getLogger } from '../../shared/logger/logger'
32- import { CancellationError , Timeout } from '../../shared/utilities/timeoutUtils'
32+ import { CancellationError , Timeout , waitUntil } from '../../shared/utilities/timeoutUtils'
3333import { showMessageWithCancel } from '../../shared/utilities/messages'
3434import { SshConfig } from '../../shared/sshConfig'
3535import { SshKeyPair } from './sshKeyPair'
@@ -150,8 +150,14 @@ export class Ec2Connecter implements vscode.Disposable {
150150 }
151151 }
152152
153- private async checkForInstanceSsmError ( selection : Ec2Selection ) : Promise < void > {
154- const isSsmAgentRunning = ( await this . ssmClient . getInstanceAgentPingStatus ( selection . instanceId ) ) === 'Online'
153+ public async checkForInstanceSsmError (
154+ selection : Ec2Selection ,
155+ options ?: Partial < { interval : number ; timeout : number } >
156+ ) : Promise < void > {
157+ const isSsmAgentRunning = await waitUntil (
158+ async ( ) => ( await this . ssmClient . getInstanceAgentPingStatus ( selection . instanceId ) ) === 'Online' ,
159+ { interval : options ?. interval ?? 500 , timeout : options ?. timeout ?? 5000 }
160+ )
155161
156162 if ( ! isSsmAgentRunning ) {
157163 this . throwConnectionError ( 'Is SSM Agent running on the target instance?' , selection , {
Original file line number Diff line number Diff line change @@ -125,6 +125,17 @@ describe('Ec2ConnectClient', function () {
125125 }
126126 } )
127127
128+ it ( 'retries if agent status is not online' , async function ( ) {
129+ const instanceAgentStatus = sinon . stub ( SsmClient . prototype , 'getInstanceAgentPingStatus' )
130+ instanceAgentStatus . onFirstCall ( ) . resolves ( 'Offline' )
131+ instanceAgentStatus . onSecondCall ( ) . resolves ( 'Online' )
132+ try {
133+ await client . checkForInstanceSsmError ( instanceSelection , { interval : 10 , timeout : 100 } )
134+ } catch ( err ) {
135+ assert . ok ( false , `checkForInstanceSsmError failed with error '${ err } '` )
136+ }
137+ } )
138+
128139 it ( 'does not throw an error if all checks pass' , async function ( ) {
129140 sinon . stub ( Ec2Connecter . prototype , 'isInstanceRunning' ) . resolves ( true )
130141 sinon . stub ( Ec2Connecter . prototype , 'getAttachedIamRole' ) . resolves ( { Arn : 'testRole' } as IAM . Role )
You can’t perform that action at this time.
0 commit comments