mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
UX Changes:
- Added a `--galaxy` option to selftest to run tests against galaxy.
Self-test will NOT run those tests without this option. Self-test will not run any
other tests WITH this option.
The motivation here is two-fold:
- We want to make it easy to use self-test to test Galaxy without running a bunch
of extra tests. At least, we want this right now, while Galaxy is still in development.
- Galaxy is currently pretty unstable&slow; we don't want to run our regular test suite against
Galaxy all the time and slow down the tool development process. Additionally, the environment
variables required by Galaxy are a pain to set.
This is a TEMPORARY situation. Eventually, we will want to either merge the two tests together
(especially once we rotate out Mother...) or we will have a separate unrelated Galaxy test suite
and move a lot of this stuff here. With time, it will also become more obvious what a better default
(run Galaxy tests always/run Galaxy tests never/run non-Galaxy-specific tests against Galaxy) is.
The changes should be pretty self-contained.
- Added some number of environment variables to use with --galaxy tests. This is a bit complicated
and will be documented in
https://mdg.hackpad.com/GalaxyECS-Admin-tasks-RTXJ5YW8pDv#:h=Testing-Galaxy-with-selftest.
Walkthrough:
- galaxy-utls.js contains basic utils for running Galaxy tests. Use environment variables, etc.
- galaxy.js contains the acutal test
- simple-app is an app that responds to HTTP requests and serves some html that we can test to be running
- minor changes to config.js to allow overriding of the domain name
- minor changes to auth.js to allow us to automatically login as the (new) test user and use that
login to start a DDP collection.
- move a function out of deploy-settings.js into test-utils.js
- some minor additions to test-utils.js
Reviewed in https://github.com/meteor/meteor/pull/4997.
270 lines
8.8 KiB
JavaScript
270 lines
8.8 KiB
JavaScript
var _ = require('underscore');
|
|
var selftest = require('../tool-testing/selftest.js');
|
|
var testUtils = require('../tool-testing/test-utils.js');
|
|
var galaxyUtils = require('../tool-testing/galaxy-utils.js');
|
|
var Sandbox = selftest.Sandbox;
|
|
|
|
// XXX: There is currently no cleanup function in self-test, but it would be
|
|
// nice to have.
|
|
|
|
// Check if a given app is running. Curl that appname and see that it returns
|
|
// some text.
|
|
//
|
|
// - appUrl: the URL at which the app is (theoretically) running. For example
|
|
// "xxx.galaxy.meteor.com"
|
|
// - checks: what to check for. Following options:
|
|
// - text: text in the HTTP response of the app
|
|
// - containerCount: number of containers GalaxyAPI thinks is running
|
|
var checkAppIsRunning = selftest.markStack(function (appUrl, checks) {
|
|
var containerCount = checks.containerCount || 1;
|
|
var text = checks.text;
|
|
|
|
// Check that GalaxyAPI thinks that we are running the correct containers.
|
|
var appRecord = galaxyUtils.getAppRecordByName(appUrl);
|
|
selftest.expectEqual(appRecord.containerCount, containerCount);
|
|
|
|
// Ignore HTTP checks, and that's what this is.
|
|
if (! galaxyUtils.ignoreHttpChecks()) {
|
|
// Test that the app is actually running on Galaxy.
|
|
var run = galaxyUtils.curlToGalaxy(appUrl);
|
|
run.waitSecs(5);
|
|
run.matchErr(galaxyUtils.httpOK);
|
|
run.match(text);
|
|
run.expectExit(0);
|
|
}
|
|
});
|
|
|
|
// Deploy a simple app to Galaxy.
|
|
selftest.define('galaxy deploy - simple', ['galaxy'], function () {
|
|
galaxyUtils.sanityCheck();
|
|
var s = new Sandbox;
|
|
|
|
// Login with a valid Galaxy account
|
|
galaxyUtils.loginToGalaxy(s);
|
|
|
|
// Deploy an app.
|
|
var appName = galaxyUtils.createAndDeployApp(s);
|
|
|
|
// Test that the app is actually running on Galaxy.
|
|
checkAppIsRunning(appName, { text: "Hello" });
|
|
|
|
// Edit the app. Use words that are unlikely to show up in (for example)
|
|
// boilerplate 404 text.
|
|
var newText =
|
|
"<head> second </head>" + "\n" +
|
|
"<body> deploying rocks! </body>";
|
|
s.write("simple.html", newText);
|
|
|
|
// Let's use normal deploy here.
|
|
var run = s.run("deploy", appName);
|
|
run.waitSecs(15);
|
|
run.expectExit(0);
|
|
galaxyUtils.waitForContainers();
|
|
checkAppIsRunning(appName, { text: "second" });
|
|
|
|
// Delete our deployed app.
|
|
galaxyUtils.cleanUpApp(s, appName);
|
|
|
|
// Test that the app is no longer running.
|
|
// Check that GalaxyAPI thinks that we are running the correct containers.
|
|
if (! galaxyUtils.ignoreHttpChecks()) {
|
|
run = galaxyUtils.curlToGalaxy(appName);
|
|
run.waitSecs(5);
|
|
run.matchErr("404");
|
|
run.expectExit(0);
|
|
}
|
|
|
|
testUtils.logout(s);
|
|
});
|
|
|
|
// Deploy an app with some public settings to galaxy, check that everything works.
|
|
selftest.define('galaxy deploy - settings', ['galaxy'], function () {
|
|
galaxyUtils.sanityCheck();
|
|
var s = new Sandbox;
|
|
|
|
// Login with a valid Galaxy account
|
|
galaxyUtils.loginToGalaxy(s);
|
|
|
|
// Create sample settings.
|
|
var settings = {
|
|
'public': { a: 'b' }
|
|
};
|
|
|
|
// Deploy an app with settings and check that the public settings
|
|
// appear in the HTTP response body.
|
|
var appName = galaxyUtils.createAndDeployApp(s, {
|
|
settings: settings
|
|
});
|
|
|
|
// Test that the app is actually running on Galaxy.
|
|
checkAppIsRunning(appName, { text: "Hello" });
|
|
|
|
// Test that the public settins appear in the HTTP response body.
|
|
if (! galaxyUtils.ignoreHttpChecks()) {
|
|
testUtils.checkForSettings(appName, settings, 10);
|
|
}
|
|
|
|
// Re-deploy without settings and check that the settings still
|
|
// appear.
|
|
s.cd('..');
|
|
galaxyUtils.createAndDeployApp(s, {
|
|
templateApp: 'standard-app',
|
|
appName: appName,
|
|
useOldSettings: true
|
|
});
|
|
if (! galaxyUtils.ignoreHttpChecks()) {
|
|
testUtils.checkForSettings(appName, settings, 10);
|
|
}
|
|
|
|
// Re-deploy with new settings and check that the settings get
|
|
// updated.
|
|
settings['public'].a = 'c';
|
|
s.cd('..');
|
|
galaxyUtils.createAndDeployApp(s, {
|
|
templateApp: 'simple-app',
|
|
appName: appName,
|
|
settings: settings
|
|
});
|
|
checkAppIsRunning(appName, { text: "Hello" });
|
|
|
|
galaxyUtils.cleanUpApp(s, appName);
|
|
testUtils.logout(s);
|
|
});
|
|
|
|
|
|
// Rescale the app and check status.
|
|
selftest.define('galaxy deploy - rescale', ['galaxy'], function () {
|
|
galaxyUtils.sanityCheck();
|
|
var s = new Sandbox;
|
|
|
|
// Login with a valid Galaxy account
|
|
galaxyUtils.loginToGalaxy(s);
|
|
|
|
// Deploy an app.
|
|
var appName = galaxyUtils.createAndDeployApp(s);
|
|
checkAppIsRunning(appName, { text: "Hello" });
|
|
|
|
// Call into the Galaxy API DDP methods to rescale containers. The method
|
|
// signature is:
|
|
// setContainerCount: function(appId, containerCount)
|
|
var conn = galaxyUtils.loggedInGalaxyAPIConnection();
|
|
var appRecord = galaxyUtils.getAppRecordByName(appName);
|
|
galaxyUtils.callGalaxyAPI(conn, "setContainerCount", appRecord._id, 5);
|
|
galaxyUtils.waitForContainers();
|
|
checkAppIsRunning(appName, { text: "Hello", containerCount : 5 });
|
|
|
|
// More throughly: check that as far as we know, containers are actually
|
|
// running (or the scheduler is lying to GalaxyAPI and claiming that they are
|
|
// running). This API is even more internal, but it is unlikely to change for
|
|
// now.
|
|
// XXX: This subscription is not yet worth checking on staging, when it is, uncomment.
|
|
/// var containers = galaxyUtils.getAppContainerStatuses(appRecord._id, appName);
|
|
// selftest.equals(containers.length, 5);
|
|
|
|
// Now, scale down the app.
|
|
galaxyUtils.callGalaxyAPI(conn, "setContainerCount", appRecord._id, 1);
|
|
galaxyUtils.waitForContainers();
|
|
checkAppIsRunning(appName, { text: "Hello", containerCount : 1 });
|
|
|
|
// Delete the app.
|
|
galaxyUtils.cleanUpApp(s, appName);
|
|
|
|
// Check that no containers are running.
|
|
conn = galaxyUtils.renewConnection(conn);
|
|
// XXX: This subscription is not yet worth checking on staging, when it is, uncomment.
|
|
// containers = galaxyUtils.getAppContainerStatuses(appRecord._id, appName);
|
|
// selftest.expectEqual(0, containers.length);
|
|
|
|
// Logout.
|
|
galaxyUtils.closeGalaxyConnection(conn);
|
|
testUtils.logout(s);
|
|
});
|
|
|
|
// Upload an app, allocate it a self-signed cert, check that we get https
|
|
// redirection.
|
|
selftest.define('galaxy self-signed cert', ['galaxy'], function () {
|
|
galaxyUtils.sanityCheck();
|
|
var s = new Sandbox;
|
|
|
|
// Login with a valid Galaxy account
|
|
galaxyUtils.loginToGalaxy(s);
|
|
|
|
// Deploy an app. Check that it is running.
|
|
var appName = galaxyUtils.createAndDeployApp(s);
|
|
checkAppIsRunning(appName, { text: "Hello" });
|
|
|
|
// Force SSL.
|
|
var run = s.run("add", "force-ssl");
|
|
run.waitSecs(5);
|
|
run.expectExit(0);
|
|
run = s.run("deploy", appName);
|
|
run.waitSecs(30);
|
|
run.expectExit(0);
|
|
galaxyUtils.waitForContainers();
|
|
|
|
// Create a signed certificate for the app.
|
|
// createSelfSignedCertificateForApp: function (appId, options) {
|
|
var appRecord = galaxyUtils.getAppRecordByName(appName);
|
|
var conn = galaxyUtils.loggedInGalaxyAPIConnection();
|
|
var certIds = _.map(_.range(0, 15), function () {
|
|
return galaxyUtils.callGalaxyAPI(
|
|
conn, "createSelfSignedCertificateForApp", appRecord._id);
|
|
});
|
|
|
|
// Activate a certificate in the middle -- not the first or the last.
|
|
galaxyUtils.callGalaxyAPI(
|
|
conn, "activateCertificateForApp", certIds[3], appRecord._id);
|
|
// Check that we are getting a re-direct.
|
|
galaxyUtils.waitForContainers();
|
|
appRecord = galaxyUtils.getAppRecordByName(appName);
|
|
selftest.expectEqual(appRecord.containerCount, 1);
|
|
var activeCert = appRecord["activeCertificateId"];
|
|
selftest.expectEqual(activeCert, certIds[3]);
|
|
if (! galaxyUtils.ignoreHttpChecks()) {
|
|
run = galaxyUtils.curlToGalaxy(appName);
|
|
run.waitSecs(5);
|
|
run.matchErr("SSL");
|
|
run.expectExit(60);
|
|
}
|
|
|
|
// Remove the un-activated certificates
|
|
_.each(_.range(0, 15), function (i) {
|
|
if (i !== 3) {
|
|
galaxyUtils.callGalaxyAPI(
|
|
conn, "removeCertificateFromApp", certIds[i], appRecord._id);
|
|
}
|
|
});
|
|
// Check that we are still getting a re-direct and GalaxyAPI thinks that we
|
|
// are using the same cert.
|
|
appRecord = galaxyUtils.getAppRecordByName(appName);
|
|
selftest.expectEqual(appRecord["activeCertificateId"], activeCert);
|
|
if (! galaxyUtils.ignoreHttpChecks()) {
|
|
run = galaxyUtils.curlToGalaxy(appName);
|
|
run.waitSecs(5);
|
|
run.matchErr("SSL");
|
|
run.expectExit(60);
|
|
}
|
|
|
|
// Clean up.
|
|
galaxyUtils.cleanUpApp(s, appName);
|
|
testUtils.logout(s);
|
|
galaxyUtils.closeGalaxyConnection(conn);
|
|
});
|
|
|
|
// Unauthorized users cannot deploy to Galaxy.
|
|
selftest.define('unauthorized deploy', ['galaxy'], function () {
|
|
var sandbox = new Sandbox;
|
|
// This is the test user. The test user is not currently authorized to deploy
|
|
// to Galaxy. Sorry, test user! :( Hopefully, someday.
|
|
testUtils.login(sandbox, 'test', 'testtest');
|
|
|
|
var appName = testUtils.randomAppName();
|
|
sandbox.createApp(appName, 'empty');
|
|
sandbox.cd(appName);
|
|
var run = sandbox.run("deploy", appName);
|
|
run.waitSecs(90);
|
|
run.matchErr("Error deploying");
|
|
run.matchErr("is not authorized");
|
|
run.expectExit(1);
|
|
});
|