Skip to content

Commit ab866b0

Browse files
committed
Implement cluster support for testing
1 parent 5d78583 commit ab866b0

29 files changed

+141
-178
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ TEST_ARANGODB_URL=http://myserver.local:8530 npm test
3030
TEST_ARANGODB_URL=http://myserver.local:8530 yarn test
3131
```
3232

33+
To run tests against a cluster, you can use multiple comma-separated URLs or
34+
append a comma to the URL. The tests will automatically attempt to acquire a
35+
host list and use round robin load balancing.
36+
3337
For development arangojs tracks the development build of ArangoDB. This means
3438
tests may reflect behavior that does not match any existing public release of
3539
ArangoDB.

src/test/01-manipulating-databases.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { expect } from "chai";
22
import { Database } from "../database";
33
import { ArangoError } from "../error";
4-
5-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
6-
const ARANGO_VERSION = Number(
7-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
8-
);
4+
import { config } from "./_config";
95

106
describe("Manipulating databases", function () {
117
let db: Database;
12-
beforeEach(() => {
13-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
8+
beforeEach(async () => {
9+
db = new Database(config);
10+
if (Array.isArray(config.url)) await db.acquireHostList();
1411
});
1512
afterEach(() => {
1613
db.close();

src/test/02-accessing-collections.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { expect } from "chai";
22
import { ArangoCollection, isArangoCollection } from "../collection";
33
import { Database } from "../database";
4+
import { config } from "./_config";
45

56
const range = (n: number): number[] => Array.from(Array(n).keys());
67

7-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
8-
const ARANGO_VERSION = Number(
9-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
10-
);
11-
128
describe("Accessing collections", function () {
139
const name = `testdb_${Date.now()}`;
1410
let db: Database;
1511
let builtinSystemCollections: string[];
1612
before(async () => {
17-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
13+
db = new Database(config);
14+
if (Array.isArray(config.url)) await db.acquireHostList();
1815
await db.createDatabase(name);
1916
db.useDatabase(name);
2017
const collections = await db.listCollections(false);

src/test/03-accessing-graphs.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ import { expect } from "chai";
22
import { ArangoCollection } from "../collection";
33
import { Database } from "../database";
44
import { Graph } from "../graph";
5+
import { config } from "./_config";
56

67
const range = (n: number): number[] => Array.from(Array(n).keys());
78

8-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
9-
const ARANGO_VERSION = Number(
10-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
11-
);
12-
139
describe("Accessing graphs", function () {
1410
const name = `testdb_${Date.now()}`;
1511
let db: Database;
1612
before(async () => {
17-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
13+
db = new Database(config);
14+
if (Array.isArray(config.url)) await db.acquireHostList();
1815
await db.createDatabase(name);
1916
db.useDatabase(name);
2017
});

src/test/04-transactions.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { expect } from "chai";
22
import { DocumentCollection } from "../collection";
33
import { Database } from "../database";
4+
import { config } from "./_config";
45

5-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
6-
const ARANGO_VERSION = Number(
7-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
8-
);
9-
const describe35 = ARANGO_VERSION >= 30500 ? describe : describe.skip;
6+
const describe35 = config.arangoVersion! >= 30500 ? describe : describe.skip;
107
const itRdb = process.env.ARANGO_STORAGE_ENGINE !== "mmfiles" ? it : it.skip;
118

129
describe("Transactions", () => {
1310
let db: Database;
14-
before(() => {
15-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
11+
before(async () => {
12+
db = new Database(config);
13+
if (Array.isArray(config.url)) await db.acquireHostList();
1614
});
1715
after(() => {
1816
db.close();

src/test/06-managing-functions.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { expect } from "chai";
22
import { Database } from "../database";
3+
import { config } from "./_config";
34

4-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
5-
const ARANGO_VERSION = Number(
6-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
7-
);
8-
const it34 = ARANGO_VERSION >= 30400 ? it : it.skip;
5+
const it34 = config.arangoVersion! >= 30400 ? it : it.skip;
96

107
describe("Managing functions", function () {
118
const name = `testdb_${Date.now()}`;
129
let db: Database;
1310
before(async () => {
14-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
11+
db = new Database(config);
12+
if (Array.isArray(config.url)) await db.acquireHostList();
1513
await db.createDatabase(name);
1614
db.useDatabase(name);
1715
});
@@ -60,7 +58,7 @@ describe("Managing functions", function () {
6058
"function (celsius) { return celsius * 1.8 + 32; }"
6159
);
6260
const info = await db.dropFunction(name);
63-
if (ARANGO_VERSION >= 30400)
61+
if (config.arangoVersion! >= 30400)
6462
expect(info).to.have.property("deletedCount", 1);
6563
});
6664
});

src/test/07-routes.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ import { expect } from "chai";
22
import { DocumentCollection } from "../collection";
33
import { Database } from "../database";
44
import { Route } from "../route";
5-
6-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
7-
const ARANGO_VERSION = Number(
8-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
9-
);
5+
import { config } from "./_config";
106

117
describe("Arbitrary HTTP routes", () => {
12-
const db = new Database({
13-
url: ARANGO_URL,
14-
arangoVersion: ARANGO_VERSION,
8+
let db: Database;
9+
before(async () => {
10+
db = new Database(config);
11+
if (Array.isArray(config.url)) await db.acquireHostList();
1512
});
1613
describe("database.route", () => {
1714
it("returns a Route instance", () => {
@@ -35,7 +32,8 @@ describe("Route API", function () {
3532
let db: Database;
3633
let collection: DocumentCollection;
3734
before(async () => {
38-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
35+
db = new Database(config);
36+
if (Array.isArray(config.url)) await db.acquireHostList();
3937
await db.createDatabase(name);
4038
db.useDatabase(name);
4139
collection = await db.createCollection(`c_${Date.now()}`);

src/test/08-cursors.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@ import { LinkedList } from "x3-linkedlist";
33
import { aql } from "../aql";
44
import { ArrayCursor, BatchedArrayCursor } from "../cursor";
55
import { Database } from "../database";
6-
7-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
8-
const ARANGO_VERSION = Number(
9-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
10-
);
6+
import { config } from "./_config";
117

128
const aqlQuery = aql`FOR i IN 0..10 RETURN i`;
139
const aqlResult = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
1410

1511
async function sleep(ms: number) {
16-
return new Promise((resolve) => {
12+
return new Promise<void>((resolve) => {
1713
setTimeout(() => resolve(), ms);
1814
});
1915
}
2016

2117
describe("Item-wise Cursor API", () => {
2218
let db: Database;
2319
let cursor: ArrayCursor;
24-
before(() => {
25-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
20+
before(async () => {
21+
db = new Database(config);
22+
if (Array.isArray(config.url)) await db.acquireHostList();
2623
});
2724
after(() => {
2825
db.close();
@@ -223,8 +220,9 @@ describe("Item-wise Cursor API", () => {
223220
describe("Batch-wise Cursor API", () => {
224221
let db: Database;
225222
let cursor: BatchedArrayCursor;
226-
before(() => {
227-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
223+
before(async () => {
224+
db = new Database(config);
225+
if (Array.isArray(config.url)) await db.acquireHostList();
228226
});
229227
after(() => {
230228
db.close();

src/test/09-collection-metadata.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ import { expect } from "chai";
22
import { DocumentCollection } from "../collection";
33
import { Database } from "../database";
44
import { COLLECTION_NOT_FOUND } from "../lib/codes";
5-
6-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
7-
const ARANGO_VERSION = Number(
8-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
9-
);
5+
import { config } from "./_config";
106

117
describe("Collection metadata", function () {
128
let db: Database;
139
let collection: DocumentCollection;
1410
const dbName = `testdb_${Date.now()}`;
1511
const collectionName = `collection-${Date.now()}`;
1612
before(async () => {
17-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
13+
db = new Database(config);
14+
if (Array.isArray(config.url)) await db.acquireHostList();
1815
await db.createDatabase(dbName);
1916
db.useDatabase(dbName);
2017
collection = await db.createCollection(collectionName);

src/test/10-manipulating-collections.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import { expect } from "chai";
22
import { DocumentCollection } from "../collection";
33
import { Database } from "../database";
4-
5-
const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529";
6-
const ARANGO_VERSION = Number(
7-
process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 30400
8-
);
4+
import { config } from "./_config";
95

106
describe("Manipulating collections", function () {
117
const name = `testdb_${Date.now()}`;
128
let db: Database;
139
let collection: DocumentCollection;
1410
before(async () => {
15-
db = new Database({ url: ARANGO_URL, arangoVersion: ARANGO_VERSION });
11+
db = new Database(config);
12+
if (Array.isArray(config.url)) await db.acquireHostList();
1613
await db.createDatabase(name);
1714
db.useDatabase(name);
1815
});

0 commit comments

Comments
 (0)