This commit is contained in:
Steve Faulkner 2019-08-20 12:44:33 -05:00 коммит произвёл GitHub
Родитель abb2c44703
Коммит f34c4cda26
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 36 добавлений и 21 удалений

Просмотреть файл

@ -215,3 +215,22 @@ export function replaceOrUpsertPermission(
return user.permission(body.id).replace(body, options);
}
}
export function generateDocuments(docSize: number) {
const docs = [];
for (let i = 0; i < docSize; i++) {
const d = {
id: i.toString(),
name: "sample document",
spam: "eggs" + i.toString(),
cnt: i,
key: "value",
spam2: i === 3 ? "eggs" + i.toString() : i,
spam3: `eggs${i % 3}`,
boolVar: i % 2 === 0,
number: 1.1 * i
};
docs.push(d);
}
return docs;
}

Просмотреть файл

@ -2,14 +2,14 @@ import assert from "assert";
import { Agent } from "http";
import { CosmosClient } from "../../dist-esm";
import { endpoint, masterKey } from "../common/_testConfig";
import { getTestDatabase } from "../common/TestHelpers";
import { getTestDatabase, getTestContainer, generateDocuments, bulkInsertItems } from "../common/TestHelpers";
import { AbortController } from "abort-controller";
describe("NodeJS CRUD Tests", function() {
this.timeout(process.env.MOCHA_TIMEOUT || 20000);
describe("Validate client request timeout", function() {
it("nativeApi Client Should throw exception", async function() {
it("timeout occurs within expected timeframe", async function() {
// making timeout 1 ms to make sure it will throw
// (create database request takes 10ms-15ms to finish on emulator)
const client = new CosmosClient({ endpoint, key: masterKey, connectionPolicy: { requestTimeout: 1 } });
@ -64,5 +64,19 @@ describe("NodeJS CRUD Tests", function() {
assert.equal(err.name, "AbortError", "client should throw exception");
}
});
it("should abort a query", async function() {
const container = await getTestContainer("abort query");
await bulkInsertItems(container, generateDocuments(20));
try {
const controller = new AbortController();
const signal = controller.signal;
setTimeout(() => controller.abort(), 5000);
// Setting maxItemCount = 1 to ensure this query take a long time
await container.items.query("SELECT * from c", { abortSignal: signal, maxItemCount: 1 }).fetchAll();
assert.fail("Must throw");
} catch (err) {
assert.equal(err.name, "AbortError", "client should throw exception");
}
});
});
});

Просмотреть файл

@ -4,7 +4,7 @@ import { Container, ContainerDefinition } from "../../dist-esm/client";
import { DataType, IndexKind } from "../../dist-esm/documents";
import { SqlQuerySpec } from "../../dist-esm/queryExecutionContext";
import { QueryIterator } from "../../dist-esm/queryIterator";
import { bulkInsertItems, getTestContainer, removeAllDatabases } from "../common/TestHelpers";
import { bulkInsertItems, getTestContainer, removeAllDatabases, generateDocuments } from "../common/TestHelpers";
import { FeedResponse, FeedOptions } from "../../dist-esm";
function compare(key: string) {
@ -21,24 +21,6 @@ function compare(key: string) {
describe("Cross Partition", function() {
this.timeout(process.env.MOCHA_TIMEOUT || "30000");
const generateDocuments = function(docSize: number) {
const docs = [];
for (let i = 0; i < docSize; i++) {
const d = {
id: i.toString(),
name: "sample document",
spam: "eggs" + i.toString(),
cnt: i,
key: "value",
spam2: i === 3 ? "eggs" + i.toString() : i,
spam3: `eggs${i % 3}`,
boolVar: i % 2 === 0,
number: 1.1 * i
};
docs.push(d);
}
return docs;
};
describe("Validate Query", function() {
const documentDefinitions = generateDocuments(20);