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 {
29
29
testSshConnection ,
30
30
} from '../../shared/extensions/ssh'
31
31
import { getLogger } from '../../shared/logger/logger'
32
- import { CancellationError , Timeout } from '../../shared/utilities/timeoutUtils'
32
+ import { CancellationError , Timeout , waitUntil } from '../../shared/utilities/timeoutUtils'
33
33
import { showMessageWithCancel } from '../../shared/utilities/messages'
34
34
import { SshConfig } from '../../shared/sshConfig'
35
35
import { SshKeyPair } from './sshKeyPair'
@@ -150,8 +150,14 @@ export class Ec2Connecter implements vscode.Disposable {
150
150
}
151
151
}
152
152
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
+ )
155
161
156
162
if ( ! isSsmAgentRunning ) {
157
163
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 () {
125
125
}
126
126
} )
127
127
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
+
128
139
it ( 'does not throw an error if all checks pass' , async function ( ) {
129
140
sinon . stub ( Ec2Connecter . prototype , 'isInstanceRunning' ) . resolves ( true )
130
141
sinon . stub ( Ec2Connecter . prototype , 'getAttachedIamRole' ) . resolves ( { Arn : 'testRole' } as IAM . Role )
You can’t perform that action at this time.
0 commit comments