2
  • Tests run (and Redis works) perfectly fine in a local environment
  • Redis works normally even when deployed to production
  • However Redis connections immediately close when run in Heroku's CI test environment

Technologies used:

  • Node.js, Express, Mocha, Chai, Supertest
  • Heroku, Heroku CI, (Heroku) Redis

I'm having the tests run through the Pipeline feature. And then I get the following error output:

-----> Running test command `make test-ci`...
NODE_ENV=test ./node_modules/.bin/db-migrate up --log-level=error --env=test --config=config/database.json --migrations-dir ./db/migrations
NODE_ENV=test ./node_modules/.bin/mocha --exit --ui bdd --reporter spec --timeout 15000 --recursive ./tests/setup.js ./tests/
Redis successfully connected
  POST: API /account/phone
Redis set error The client is closed
    1) accepts a phone number and generates a PIN
  0 passing (15s)
  1 failing
  1) POST: API /account/phone
       accepts a phone number and generates a PIN:
     Error: Timeout of 15000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/app/tests/api/account.js)
  
make: *** [Makefile:66: test-ci] Error 1
-----> test command `make test-ci` failed with exit status 2

My app.json file looks like this

{
  "environments": {
    "test": {
      "scripts": {
        "test": "make test-ci"
      },
      "addons": [
        "heroku-redis:in-dyno",
        "heroku-postgresql:in-dyno"
      ]
    }
  }
}

My Redis connection file looks like this:

let redis = require('redis')
let client = redis.createClient({
  url: process.env.REDIS_URL
})
client.on('error', err => console.log('Redis Client Error', err))
client.on('connect', () => {
  console.log('Redis successfully connected')
})

The route that's being tested looks like this:

redis.set('phone:keys:' + phone, code, { EX: 60 * 5 }).then(val => {
  console.log('did it get set in redis?')
  twilio.send(phone, message).then(response => {
    res.status(201).json({
      ok: true,
      data: { body: response.body },
    })
  })
})
.catch((err) => {
  console.log('Redis set error', err.message)
})

In local env (and production), it all works normally. Even when running tests locally. But only in Heroku CI it fails, and I see the "Redis set error The client is closed "

user3242466
  • 474
  • 4
  • 7

0 Answers0