Skip to content

Commit 6b79a81

Browse files
authored
Merge pull request #257 from ml054/v4.2
V4.2
2 parents bb88bcf + 8a5844d commit 6b79a81

File tree

8 files changed

+123
-12
lines changed

8 files changed

+123
-12
lines changed

src/Documents/Changes/ChangesObservable.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ export class ChangesObservable<T, TConnectionState extends IChangesConnectionSta
5959
public off(event: "error", handler: (error: Error) => void);
6060
public off(event: "data" | "error", handler: ((value: T) => void) | ((error: Error) => void)) {
6161

62-
this._connectionState.dec();
63-
6462
switch (event) {
6563
case "data":
66-
this._subscribers.delete(handler as (value: T) => void);
64+
if (this._subscribers.delete(handler as (value: T) => void)) {
65+
this._connectionState.dec();
66+
}
67+
6768
if (!this._subscribers.size) {
6869
// no more subscribers left - remove from parent
6970
this._connectionState.removeOnChangeNotification(this._type, this._sendHandler);

src/Documents/Session/InMemoryDocumentSessionOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export abstract class InMemoryDocumentSessionOperations
460460
hasAll = hasAll && this.isLoaded(includeId);
461461
});
462462

463-
if (!hasAll[0]) {
463+
if (!hasAll) {
464464
return false;
465465
}
466466
}

test/Ported/Cluster/ClusterModesForRequestExecutorTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClusterTestContext } from "../../Utils/TestUtil";
1+
import { ClusterTestContext, RavenTestContext } from "../../Utils/TestUtil";
22
import { DocumentStore } from "../../../src/Documents/DocumentStore";
33
import { DocumentConventions } from "../../../src/Documents/Conventions/DocumentConventions";
44
import { ServerNode } from "../../../src/Http/ServerNode";
@@ -13,7 +13,7 @@ import { GetStatisticsOperation } from "../../../src/Documents/Operations/GetSta
1313
import { SessionInfo } from "../../../src/Documents/Session/IDocumentSession";
1414
import { UpdateTopologyParameters } from "../../../src/Http/UpdateTopologyParameters";
1515

16-
describe("ClusterModesForRequestExecutorTest", function () {
16+
(RavenTestContext.isPullRequest ? describe.skip : describe)("ClusterModesForRequestExecutorTest", function () {
1717

1818
let testContext: ClusterTestContext;
1919

test/Ported/Cluster/ClusterOperationTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClusterTestContext } from "../../Utils/TestUtil";
1+
import { ClusterTestContext, RavenTestContext } from "../../Utils/TestUtil";
22
import { DocumentStore } from "../../../src/Documents/DocumentStore";
33
import { NextIdentityForOperation } from "../../../src/Documents/Operations/Identities/NextIdentityForOperation";
44
import { assertThat, assertThrows } from "../../Utils/AssertExtensions";
@@ -13,7 +13,7 @@ import { GetDatabaseRecordOperation } from "../../../src/ServerWide/Operations/G
1313
import { ReorderDatabaseMembersOperation } from "../../../src/ServerWide/Operations/ReorderDatabaseMembersOperation";
1414
import { TypeUtil } from "../../../src/Utility/TypeUtil";
1515

16-
describe("ClusterOperationTest", function () {
16+
(RavenTestContext.isPullRequest ? describe.skip : describe)("ClusterOperationTest", function () {
1717

1818
const testContext = new ClusterTestContext();
1919

test/Ported/Issues/RDBC_435.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { testContext, disposeTestDocumentStore } from "../../Utils/TestUtil";
2+
3+
import {
4+
IDocumentStore, DocumentChange,
5+
} from "../../../src";
6+
import { User } from "../../Assets/Entities";
7+
import { AsyncQueue } from "../../Utils/AsyncQueue";
8+
import { throwError } from "../../../src/Exceptions";
9+
import { assertThat, assertThrows } from "../../Utils/AssertExtensions";
10+
11+
describe("RDBC_435", function () {
12+
13+
let store: IDocumentStore;
14+
15+
beforeEach(async function () {
16+
store = await testContext.getDocumentStore();
17+
});
18+
19+
afterEach(async () =>
20+
await disposeTestDocumentStore(store));
21+
22+
it("can handle data/errors on/off", async () => {
23+
24+
const createUser = async () => {
25+
const session = store.openSession();
26+
const user1 = new User();
27+
user1.age = 5;
28+
await session.store(user1);
29+
await session.saveChanges();
30+
31+
return user1.id;
32+
}
33+
34+
const changesList = new AsyncQueue<DocumentChange>();
35+
36+
const changes = store.changes();
37+
await changes.ensureConnectedNow();
38+
39+
const observable = changes.forDocumentsInCollection("users");
40+
await observable.ensureSubscribedNow();
41+
42+
const handler = (change: DocumentChange) => changesList.push(change);
43+
44+
const errorHandler = e => throwError("InvalidOperationException", e.message);
45+
46+
observable.on("data", handler);
47+
observable.on("error", errorHandler);
48+
49+
const user1Id = await createUser();
50+
51+
const change1 = await changesList.poll(15_000);
52+
assertThat(change1)
53+
.isNotNull();
54+
assertThat(change1.id)
55+
.isEqualTo(user1Id);
56+
57+
// now disable error handler, create next user and wait for change
58+
observable.off("error", errorHandler);
59+
60+
const user2Id = await createUser();
61+
62+
const change2 = await changesList.poll(15_000);
63+
assertThat(change2)
64+
.isNotNull();
65+
assertThat(change2.id)
66+
.isEqualTo(user2Id);
67+
68+
// disable data handle - not we shouldn't get any data
69+
70+
observable.off("data", handler);
71+
await createUser();
72+
73+
await assertThrows(async () => changesList.poll(3_000), err => {
74+
assertThat(err.name)
75+
.isEqualTo("TimeoutException");
76+
});
77+
});
78+
});

test/Ported/Issues/RDBC_440.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { IDocumentStore } from "../../../src";
2+
import { disposeTestDocumentStore, testContext } from "../../Utils/TestUtil";
3+
import { User } from "../../Assets/Entities";
4+
import { assertThat } from "../../Utils/AssertExtensions";
5+
6+
describe("RDBC_440", function () {
7+
8+
let store: IDocumentStore;
9+
10+
beforeEach(async function () {
11+
store = await testContext.getDocumentStore();
12+
});
13+
14+
afterEach(async () =>
15+
await disposeTestDocumentStore(store));
16+
17+
it("can load just added entity", async () => {
18+
const session = store.openSession();
19+
const user1 = Object.assign(new User(), {
20+
name: "Marcin",
21+
id: "users/1"
22+
});
23+
24+
await session.store(user1);
25+
const loadedUser = await session
26+
.include("addressId")
27+
.load("users/1")
28+
29+
assertThat(loadedUser)
30+
.isSameAs(user1);
31+
});
32+
});

test/Ported/RequestExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { DocumentStore, EntityToJson, IDocumentStore, PutDocumentCommand } from "../../src";
2-
import { ClusterTestContext, disposeTestDocumentStore, testContext } from "../Utils/TestUtil";
2+
import { ClusterTestContext, disposeTestDocumentStore, RavenTestContext, testContext } from "../Utils/TestUtil";
33
import { throwError } from "../../src/Exceptions";
44
import { HttpRequestParameters, HttpResponse } from "../../src/Primitives/Http";
55
import * as stream from "readable-stream";
66
import * as http from "http";
77
import { User } from "../Assets/Entities";
88
import { assertThat } from "../Utils/AssertExtensions";
99

10-
describe("RequestExecutor", function () {
10+
(RavenTestContext.isPullRequest ? describe.skip : describe)("RequestExecutor", function () {
1111

1212
let store: IDocumentStore;
1313

test/Ported/Server/Replication/ReplicationWriteAssuranceTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { ClusterTestContext } from "../../../Utils/TestUtil";
1+
import { ClusterTestContext, RavenTestContext } from "../../../Utils/TestUtil";
22
import { DocumentStore } from "../../../../src/Documents/DocumentStore";
33
import { User } from "../../../Assets/Entities";
44
import { assertThat } from "../../../Utils/AssertExtensions";
55

6-
describe("ReplicationWriteAssuranceTest", function () {
6+
(RavenTestContext.isPullRequest ? describe.skip : describe)("ReplicationWriteAssuranceTest", function () {
77

88
const testContext = new ClusterTestContext();
99

0 commit comments

Comments
 (0)