Revert "Remove channel reference counter"

This reverts commit d678fa56d1.  The
reference counter, flawed as it is, was masking far more issues than I
realized.  It would require a more significant rearchitecture of the
code to remove it.  Probably better to keep it and try to improve it for
now.
This commit is contained in:
Calvin Montgomery 2021-01-09 13:03:38 -08:00
parent 3262f7822f
commit 00e9acbe4d
9 changed files with 158 additions and 64 deletions

View file

@ -16,6 +16,10 @@ describe('KickbanModule', () => {
beforeEach(() => {
mockChannel = {
name: channelName,
refCounter: {
ref() { },
unref() { }
},
logger: {
log() { }
},
@ -65,22 +69,11 @@ describe('KickbanModule', () => {
});
});
function patch(fn, after) {
let existing = kickban[fn];
kickban[fn] = async function () {
try {
await existing.apply(this, arguments)
} finally {
after();
}
};
}
describe('#handleCmdBan', () => {
it('inserts a valid ban', done => {
let kicked = false;
patch('banName', () => {
mockChannel.refCounter.unref = () => {
assert(kicked, 'Expected user to be kicked');
database.getDB().runTransaction(async tx => {
@ -97,7 +90,7 @@ describe('KickbanModule', () => {
done();
});
});
};
mockChannel.users = [{
getLowerName() {
@ -254,7 +247,7 @@ describe('KickbanModule', () => {
let firstUserKicked = false;
let secondUserKicked = false;
patch('banAll', () => {
mockChannel.refCounter.unref = () => {
assert(firstUserKicked, 'Expected banned user to be kicked');
assert(
secondUserKicked,
@ -286,7 +279,7 @@ describe('KickbanModule', () => {
done();
});
});
};
mockChannel.users = [{
getLowerName() {
@ -320,7 +313,7 @@ describe('KickbanModule', () => {
});
it('inserts a valid range ban', done => {
patch('banIP', () => {
mockChannel.refCounter.unref = () => {
database.getDB().runTransaction(async tx => {
const ipBan = await tx.table('channel_bans')
.where({
@ -335,7 +328,7 @@ describe('KickbanModule', () => {
done();
});
});
};
kickban.handleCmdIPBan(
mockUser,
@ -345,7 +338,7 @@ describe('KickbanModule', () => {
});
it('inserts a valid wide-range ban', done => {
patch('banIP', () => {
mockChannel.refCounter.unref = () => {
database.getDB().runTransaction(async tx => {
const ipBan = await tx.table('channel_bans')
.where({
@ -360,7 +353,7 @@ describe('KickbanModule', () => {
done();
});
});
};
kickban.handleCmdIPBan(
mockUser,
@ -372,7 +365,7 @@ describe('KickbanModule', () => {
it('inserts a valid IPv6 ban', done => {
const longIP = require('../../lib/utilities').expandIPv6('::abcd');
patch('banAll', () => {
mockChannel.refCounter.unref = () => {
database.getDB().runTransaction(async tx => {
const ipBan = await tx.table('channel_bans')
.where({
@ -387,7 +380,7 @@ describe('KickbanModule', () => {
done();
});
});
};
database.getDB().runTransaction(async tx => {
await tx.table('aliases')
@ -553,7 +546,7 @@ describe('KickbanModule', () => {
});
it('still adds the IP ban even if the name is already banned', done => {
patch('banIP', () => {
mockChannel.refCounter.unref = () => {
database.getDB().runTransaction(async tx => {
const ipBan = await tx.table('channel_bans')
.where({
@ -568,7 +561,7 @@ describe('KickbanModule', () => {
done();
});
});
};
database.getDB().runTransaction(tx => {
return tx.table('channel_bans')