Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle missing db properly in test and prod. Fixes #4. #10

Merged
merged 2 commits into from

2 participants

@6a68
Owner

@jedp updated, mind merging in?

The if !db lines accommodate unit testing without redis running/installed.

Modify those lines to return 200/[] if testing, or 500 if in prod.

If we fill up the redis DB again, or it crashes or whatever, the service will stop infuriatingly telling you you've got zero emails. This is good.

@6a68
Owner

Updated to add the ISO timestamps that were so incredibly helpful when debugging deployer recently.

@6a68
Owner

I should add that 1/6 unit tests fails before and after this change, with redis turned off, and all tests pass before and after, with redis turned on (running on localhost).

@6a68
Owner

@rfk mind a little quid pro quo review/merge action over here? ;-)

@rfk rfk merged commit 2649fbd into mozilla:master
@6a68 6a68 deleted the 6a68:nodb branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 6 deletions.
  1. +13 −6 webserver.js
View
19 webserver.js
@@ -2,20 +2,27 @@ var express = require('express'),
redis = require("redis"),
fs = require('fs');
-const HOSTNAME = process.env['EMAIL_HOSTNAME'] || "restmail.net";
+const HOSTNAME = process.env['EMAIL_HOSTNAME'] || "restmail.net",
+ IS_TEST = process.env['NODE_ENV'] == 'test';
// create a connection to the redis datastore
var db = redis.createClient();
db.on("error", function (err) {
db = null;
- console.log("redis error! the server won't actually store anything! this is just fine for local dev");
+ if (IS_TEST) {
+ console.log(new Date().toISOString() + ": redis error! the server won't actually store anything! this is just fine for local dev")
+ } else {
+ console.log(new Date().toISOString() + ": FATAL: redis server error: " + err);
+ console.log(new Date().toISOString() + ": Exiting due to fatal error...");
+ process.exit(1);
+ }
});
var app = express.createServer();
// log to console when not testing
-if (process.env.NODE_ENV !== 'test') app.use(express.logger());
+if (!IS_TEST) app.use(express.logger());
app.get('/README', function(req, res) {
res.setHeader('Content-Type', 'text/plain');
@@ -32,13 +39,13 @@ function canonicalize(email) {
// the 'todo/get' api gets the current version of the todo list
// from the server
app.get('/mail/:user', function(req, res) {
- if (!db) res.json([]);
+ if (!db) { return IS_TEST ? res.json([]) : res.send(500) }
req.params.user = canonicalize(req.params.user);
db.lrange(req.params.user, -10, -1, function(err, replies) {
if (err) {
- console.log("ERROR", err);
+ console.log(new Date().toISOString() + ": ERROR", err);
res.send(500);
} else {
var arr = [];
@@ -53,7 +60,7 @@ app.get('/mail/:user', function(req, res) {
});
app.delete('/mail/:user', function(req, res) {
- if (!db) res.send(200);
+ if (!db) { return res.send(IS_TEST ? 200 : 500) }
req.params.user = canonicalize(req.params.user);
Something went wrong with that request. Please try again.