Removing dependency on REDIS in webhook tests

This commit is contained in:
Jarosław Sadziński 2022-12-19 18:35:13 +01:00
parent 7dc49f3c85
commit 0b6b8feb2b
2 changed files with 352 additions and 338 deletions

View File

@ -12,7 +12,7 @@
"install:python3": "buildtools/prepare_python3.sh", "install:python3": "buildtools/prepare_python3.sh",
"build:prod": "buildtools/build.sh", "build:prod": "buildtools/build.sh",
"start:prod": "sandbox/run.sh", "start:prod": "sandbox/run.sh",
"test": "GRIST_SESSION_COOKIE=grist_test_cookie GRIST_TEST_LOGIN=1 TEST_SUPPORT_API_KEY=api_key_for_support TEST_CLEAN_DATABASE=true NODE_PATH=_build:_build/stubs:_build/ext mocha ${DEBUG:+-b --no-exit} ${DEBUG:---forbid-only} -g ${GREP_TESTS:-''} _build/test/common/*.js _build/test/client/*.js _build/test/nbrowser/*.js _build/test/server/**/*.js _build/test/gen-server/**/*.js", "test": "GRIST_SESSION_COOKIE=grist_test_cookie GRIST_TEST_LOGIN=1 TEST_SUPPORT_API_KEY=api_key_for_support TEST_CLEAN_DATABASE=true NODE_PATH=_build:_build/stubs:_build/ext mocha ${DEBUG:+-b --no-exit} --slow 8000 ${DEBUG:---forbid-only} -g ${GREP_TESTS:-''} _build/test/common/*.js _build/test/client/*.js _build/test/nbrowser/*.js _build/test/server/**/*.js _build/test/gen-server/**/*.js",
"test:nbrowser": "GRIST_SESSION_COOKIE=grist_test_cookie GRIST_TEST_LOGIN=1 TEST_SUPPORT_API_KEY=api_key_for_support TEST_CLEAN_DATABASE=true NODE_PATH=_build:_build/stubs:_build/ext mocha ${DEBUG:+-b --no-exit} ${DEBUG:---forbid-only} -g ${GREP_TESTS:-''} --slow 8000 _build/test/nbrowser/**/*.js", "test:nbrowser": "GRIST_SESSION_COOKIE=grist_test_cookie GRIST_TEST_LOGIN=1 TEST_SUPPORT_API_KEY=api_key_for_support TEST_CLEAN_DATABASE=true NODE_PATH=_build:_build/stubs:_build/ext mocha ${DEBUG:+-b --no-exit} ${DEBUG:---forbid-only} -g ${GREP_TESTS:-''} --slow 8000 _build/test/nbrowser/**/*.js",
"test:client": "GRIST_SESSION_COOKIE=grist_test_cookie NODE_PATH=_build:_build/stubs:_build/ext mocha ${DEBUG:+'-b'} _build/test/client/**/*.js", "test:client": "GRIST_SESSION_COOKIE=grist_test_cookie NODE_PATH=_build:_build/stubs:_build/ext mocha ${DEBUG:+'-b'} _build/test/client/**/*.js",
"test:common": "GRIST_SESSION_COOKIE=grist_test_cookie NODE_PATH=_build:_build/stubs:_build/ext mocha ${DEBUG:+'-b'} _build/test/common/**/*.js", "test:common": "GRIST_SESSION_COOKIE=grist_test_cookie NODE_PATH=_build:_build/stubs:_build/ext mocha ${DEBUG:+'-b'} _build/test/common/**/*.js",

View File

@ -2990,7 +2990,6 @@ function testDocApi() {
before(async function() { before(async function() {
this.timeout(30000); this.timeout(30000);
if (!process.env.TEST_REDIS_URL) { this.skip(); }
requests = { requests = {
"add,update": [], "add,update": [],
"add": [], "add": [],
@ -3059,6 +3058,22 @@ function testDocApi() {
} }
}); });
}, webhooksTestPort); }, webhooksTestPort);
});
after(async function() {
await serving.shutdown();
});
describe('table endpoints', function() {
before(async function() {
this.timeout(30000);
// We rely on the REDIS server in this test.
if (!process.env.TEST_REDIS_URL) { this.skip(); }
requests = {
"add,update": [],
"add": [],
"update": [],
};
redisCalls = []; redisCalls = [];
redisMonitor = createClient(process.env.TEST_REDIS_URL); redisMonitor = createClient(process.env.TEST_REDIS_URL);
@ -3070,7 +3085,6 @@ function testDocApi() {
after(async function() { after(async function() {
if (!process.env.TEST_REDIS_URL) { this.skip(); } if (!process.env.TEST_REDIS_URL) { this.skip(); }
await serving.shutdown();
await redisMonitor.quitAsync(); await redisMonitor.quitAsync();
}); });
@ -3204,6 +3218,28 @@ function testDocApi() {
); );
}); });
});
describe("/webhooks endpoint", function() {
let docId: string;
let doc: DocAPI;
let stats: WebhookSummary[];
before(async function() {
// Create a test document.
const ws1 = (await userApi.getOrgWorkspaces('current'))[0].id;
docId = await userApi.newDoc({name: 'testdoc2'}, ws1);
doc = userApi.getDocAPI(docId);
await axios.post(`${serverUrl}/api/docs/${docId}/apply`, [
['ModifyColumn', 'Table1', 'B', {type: 'Bool'}],
], chimpy);
});
const waitForQueue = async (length: number) => {
await waitForIt(async () => {
stats = await readStats(docId);
assert.equal(length, _.sum(stats.map(x => x.usage?.numWaiting ?? 0)));
}, 1000, 200);
};
it("should clear the outgoing queue", async() => { it("should clear the outgoing queue", async() => {
// Create a test document. // Create a test document.
@ -3406,27 +3442,6 @@ function testDocApi() {
await webhook1(); await webhook1();
}); });
describe("/webhooks endpoint", function() {
let docId: string;
let doc: DocAPI;
let stats: WebhookSummary[];
before(async() => {
// Create a test document.
const ws1 = (await userApi.getOrgWorkspaces('current'))[0].id;
docId = await userApi.newDoc({name: 'testdoc2'}, ws1);
doc = userApi.getDocAPI(docId);
await axios.post(`${serverUrl}/api/docs/${docId}/apply`, [
['ModifyColumn', 'Table1', 'B', {type: 'Bool'}],
], chimpy);
});
const waitForQueue = async (length: number) => {
await waitForIt(async () => {
stats = await readStats(docId);
assert.equal(length, _.sum(stats.map(x => x.usage?.numWaiting ?? 0)));
}, 1000, 200);
};
it("should return statistics", async() => { it("should return statistics", async() => {
await clearQueue(docId); await clearQueue(docId);
// Read stats, it should be empty. // Read stats, it should be empty.
@ -3757,7 +3772,6 @@ function testDocApi() {
await unsubscribe(docId, webhook4); await unsubscribe(docId, webhook4);
}); });
}); });
}); });
describe("Allowed Origin", () => { describe("Allowed Origin", () => {