Skip to content

Commit e1b442d

Browse files
committed
Add missing query tests
1 parent f45fc8c commit e1b442d

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

src/test/27-query-management.ts

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ describe("Query Management API", function() {
136136
});
137137

138138
describe("database.setQueryTracking", () => {
139+
afterEach(async () => {
140+
await db.setQueryTracking({
141+
enabled: true,
142+
slowQueryThreshold: 5
143+
});
144+
await db.clearSlowQueries();
145+
});
139146
it("returns the AQL query tracking properties", async () => {
140147
const result = await db.setQueryTracking({
141148
enabled: true,
@@ -167,16 +174,59 @@ describe("Query Management API", function() {
167174
});
168175

169176
describe("database.listSlowQueries", () => {
170-
it("returns a list of slow queries");
177+
beforeEach(async () => {
178+
await db.setQueryTracking({
179+
enabled: true,
180+
slowQueryThreshold: 0.1,
181+
trackSlowQueries: true
182+
});
183+
await db.clearSlowQueries();
184+
});
185+
afterEach(async () => {
186+
await db.setQueryTracking({
187+
enabled: true,
188+
slowQueryThreshold: 5
189+
});
190+
await db.clearSlowQueries();
191+
});
192+
it("returns a list of slow queries", async () => {
193+
const query = "RETURN SLEEP(0.2)";
194+
await db.query(query);
195+
const queries = await db.listSlowQueries();
196+
expect(queries).to.have.lengthOf(1);
197+
expect(queries[0]).to.have.property("query", query);
198+
});
171199
});
172200

173201
describe("database.clearSlowQueries", () => {
174-
it("clears the list of slow queries");
202+
beforeEach(async () => {
203+
await db.setQueryTracking({
204+
enabled: true,
205+
slowQueryThreshold: 0.1,
206+
trackSlowQueries: true
207+
});
208+
await db.clearSlowQueries();
209+
});
210+
afterEach(async () => {
211+
await db.setQueryTracking({
212+
enabled: true,
213+
slowQueryThreshold: 5
214+
});
215+
await db.clearSlowQueries();
216+
});
217+
it("clears the list of slow queries", async () => {
218+
await db.query("RETURN SLEEP(0.2)");
219+
const queries1 = await db.listSlowQueries();
220+
expect(queries1).to.have.lengthOf(1);
221+
await db.clearSlowQueries();
222+
const queries2 = await db.listSlowQueries();
223+
expect(queries2).to.have.lengthOf(0);
224+
});
175225
});
176226

177227
describe("database.killQuery", () => {
178228
it("kills the given query", async () => {
179-
const query = "RETURN SLEEP(5)";
229+
const query = "RETURN SLEEP(0.5)";
180230
const p1 = db.query(query);
181231
const queries = await db.listRunningQueries();
182232
expect(queries).to.have.lengthOf(1);
@@ -186,6 +236,9 @@ describe("Query Management API", function() {
186236
try {
187237
await p1;
188238
} catch (e) {
239+
expect(e).to.be.instanceOf(ArangoError);
240+
expect(e).to.have.property("errorNum", 1500);
241+
expect(e).to.have.property("code", 410);
189242
return;
190243
}
191244
expect.fail();

0 commit comments

Comments
 (0)