|
3 | 3 | var assert = require('assert');
|
4 | 4 | var config = require('./lib/config');
|
5 | 5 | var helper = require('./helper');
|
| 6 | +var utils = require('../lib/utils'); |
6 | 7 | var redis = config.redis;
|
7 | 8 | var zlib = require('zlib');
|
8 | 9 | var client;
|
@@ -129,6 +130,52 @@ describe("The 'multi' method", function () {
|
129 | 130 | client = redis.createClient.apply(null, args);
|
130 | 131 | });
|
131 | 132 |
|
| 133 | + describe('monitor and transactions do not work together', function () { |
| 134 | + |
| 135 | + it('results in a execabort', function (done) { |
| 136 | + // Check that transactions in combination with monitor result in an error |
| 137 | + client.monitor(function (e) { |
| 138 | + var multi = client.multi(); |
| 139 | + multi.set('hello', 'world'); |
| 140 | + multi.exec(); |
| 141 | + client.on('error', function (err) { |
| 142 | + assert.strictEqual(err.code, 'EXECABORT'); |
| 143 | + done(e); |
| 144 | + }); |
| 145 | + }); |
| 146 | + }); |
| 147 | + |
| 148 | + it('results in a execabort #2', function (done) { |
| 149 | + // Check that using monitor with a transactions results in an error |
| 150 | + client.multi().monitor().set('foo', 'bar').exec(function (err, res) { |
| 151 | + assert.strictEqual(err.code, 'EXECABORT'); |
| 152 | + done(); |
| 153 | + }); |
| 154 | + }); |
| 155 | + |
| 156 | + it('sanity check', function (done) { |
| 157 | + // Check if Redis still has the error |
| 158 | + client.monitor(); |
| 159 | + client.send_command('multi'); |
| 160 | + client.send_command('set', ['foo', 'bar']); |
| 161 | + client.send_command('get', ['foo']); |
| 162 | + client.send_command('exec', function (err, res) { |
| 163 | + // res[0] is going to be the monitor result of set |
| 164 | + // res[1] is going to be the result of the set command |
| 165 | + assert(utils.monitor_regex.test(res[0])); |
| 166 | + assert.strictEqual(res[1], 'OK'); |
| 167 | + assert.strictEqual(res.length, 2); |
| 168 | + }); |
| 169 | + // Remove the listener and add it back again after the error |
| 170 | + var mochaListener = helper.removeMochaListener(); |
| 171 | + process.on('uncaughtException', function (err) { |
| 172 | + helper.removeMochaListener(); |
| 173 | + process.on('uncaughtException', mochaListener); |
| 174 | + done(); |
| 175 | + }); |
| 176 | + }); |
| 177 | + }); |
| 178 | + |
132 | 179 | it('executes a pipelined multi properly in combination with the offline queue', function (done) {
|
133 | 180 | var multi1 = client.multi();
|
134 | 181 | multi1.set('m1', '123');
|
|
0 commit comments