diff --git a/appstore.js b/appstore.js index efa31ee..017bd93 100644 --- a/appstore.js +++ b/appstore.js @@ -47,14 +47,16 @@ AppStore.prototype.waitForCloudron = function (boxId) { var creationTime = new Date(); process.stdout.write('Waiting for cloudron to come up.'); - var res; + var boxInfo = null, res; + while (true) { sleep(10); process.stdout.write('.'); res = request.get(this._origin + '/api/v1/cloudrons/' + boxId).query({ accessToken: this._credentials.accessToken }).end(); verifyResponse(res, 'Could not query cloudron status'); - if (res.body.box.status === 'ready') { + boxInfo = res.body.box; + if (boxInfo.status === 'ready') { debug(); break; } @@ -62,7 +64,16 @@ AppStore.prototype.waitForCloudron = function (boxId) { debug('Box created in %s minutes with IP:%s'.green, (new Date() - creationTime) / 60000, res.body.box.ip); - return res.body.box; + // even if the cloudron sent heartbeat to appstore, doesn't mean we can contact the cloudron thanks to DO networking insanity + process.stdout.write('Waiting for Cloudron to be reachable.'); + while (true) { + sleep(10); + process.stdout.write('.'); + res = request.get('https://' + boxInfo.ip).end(); + if (!res.error) break; + debug(res.error); + } + return boxInfo; }; AppStore.prototype.createCloudron = function (box) { diff --git a/test/cloudron-backup-test.js b/test/cloudron-backup-test.js index bf882ee..a733803 100644 --- a/test/cloudron-backup-test.js +++ b/test/cloudron-backup-test.js @@ -90,20 +90,19 @@ describe('Cloudron backup testing', function () { assert.strictEqual(backupInfo.dependsOn.length, 1); }); - var cloudronIp; + var boxInfo; it('can restore the box', function () { appStore.restore(box.id, backupInfo.restoreKey); - cloudronIp = appStore.waitForCloudron(box.id); + boxInfo = appStore.waitForCloudron(box.id); }); it('wait for local dns', function () { - for (var i = 0; i < 20; i++) { + for (var i = 0; i < 50; i++) { var ip = dnsSync.resolve(box.domain); - console.dir(ip, cloudronIp); - if (ip === cloudronIp) return; + if (ip === boxInfo.ip) return; - console.log('waiting for local dns to change from %s to %s', ips[0], cloudronIp); + console.log('waiting for local dns to change from %s to %s', ip, boxInfo.ip); sleep(30); } });