Make backup test more robust

This commit is contained in:
Girish Ramakrishnan 2015-07-27 13:16:19 -07:00
parent 34d77440f0
commit df80a776b1
2 changed files with 19 additions and 9 deletions

View File

@ -47,14 +47,16 @@ AppStore.prototype.waitForCloudron = function (boxId) {
var creationTime = new Date(); var creationTime = new Date();
process.stdout.write('Waiting for cloudron to come up.'); process.stdout.write('Waiting for cloudron to come up.');
var res; var boxInfo = null, res;
while (true) { while (true) {
sleep(10); sleep(10);
process.stdout.write('.'); process.stdout.write('.');
res = request.get(this._origin + '/api/v1/cloudrons/' + boxId).query({ accessToken: this._credentials.accessToken }).end(); res = request.get(this._origin + '/api/v1/cloudrons/' + boxId).query({ accessToken: this._credentials.accessToken }).end();
verifyResponse(res, 'Could not query cloudron status'); verifyResponse(res, 'Could not query cloudron status');
if (res.body.box.status === 'ready') { boxInfo = res.body.box;
if (boxInfo.status === 'ready') {
debug(); debug();
break; 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); 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) { AppStore.prototype.createCloudron = function (box) {

View File

@ -90,20 +90,19 @@ describe('Cloudron backup testing', function () {
assert.strictEqual(backupInfo.dependsOn.length, 1); assert.strictEqual(backupInfo.dependsOn.length, 1);
}); });
var cloudronIp; var boxInfo;
it('can restore the box', function () { it('can restore the box', function () {
appStore.restore(box.id, backupInfo.restoreKey); appStore.restore(box.id, backupInfo.restoreKey);
cloudronIp = appStore.waitForCloudron(box.id); boxInfo = appStore.waitForCloudron(box.id);
}); });
it('wait for local dns', function () { 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); var ip = dnsSync.resolve(box.domain);
console.dir(ip, cloudronIp); if (ip === boxInfo.ip) return;
if (ip === cloudronIp) 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); sleep(30);
} }
}); });