Skip to content

Commit

Permalink
check if the connection is already active before continuing into the …
Browse files Browse the repository at this point in the history
…waiting loop (#977)
  • Loading branch information
Jillian Tullo committed Aug 10, 2018
1 parent 4328757 commit df5fa0d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/spaces/commands/vpn/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ function * run (context, heroku) {
const interval = (typeof context.flags.interval !== 'undefined' ? context.flags.interval : 10) * 1000
const timeout = (typeof context.flags.timeout !== 'undefined' ? context.flags.timeout : 20 * 60) * 1000
const deadline = new Date(new Date().getTime() + timeout)

let lib = require('../../lib/vpn-connections')(heroku)
let info = yield lib.getVPNConnection(space, name)
if (info.status === 'active') {
cli.log('VPN has been allocated.')
return
}

const spinner = new cli.Spinner({text: `Waiting for VPN Connection ${cli.color.green(name)} to allocate...`})

spinner.start()

let lib = require('../../lib/vpn-connections')(heroku)
let info = {}
do {
info = yield lib.getVPNConnection(space, name)

if ((new Date()).getTime() >= deadline) {
throw new Error('Timeout waiting for VPN to become allocated.')
}
Expand All @@ -36,6 +40,7 @@ function * run (context, heroku) {
}

yield wait(interval)
info = yield lib.getVPNConnection(space, name)
} while (info.status !== 'active')

spinner.stop('done\n')
Expand Down
20 changes: 20 additions & 0 deletions packages/spaces/test/commands/vpn/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,24 @@ Tunnel 2 52.44.146.199 52.44.146.198 apresharedkey2 10.0.0.0/16 1
})
.then(() => api.done())
})

it('tells the user if the VPN has been allocated', function () {
let api = nock('https://api.heroku.com:443')
.get('/spaces/my-space/vpn-connections/vpn-connection-allocated')
.reply(200, {
id: '123456789012',
name: 'vpn-connection-name-config',
public_ip: '35.161.69.30',
routable_cidrs: [ '172.16.0.0/16' ],
ike_version: 1,
space_cidr_block: '10.0.0.0/16',
status: 'active',
status_message: ''
})

return cmd.run({flags: {space: 'my-space', name: 'vpn-connection-allocated', interval: 0}})
.then(() => expect(cli.stdout).to.equal(
`VPN has been allocated.\n`))
.then(() => api.done())
})
})

0 comments on commit df5fa0d

Please sign in to comment.