Skip to content

Commit 2530138

Browse files
[Multi-Tab] Spec tests for clients that gain primary lease at startup (#985)
1 parent 4c84e10 commit 2530138

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

packages/firestore/test/unit/specs/listen_spec.test.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ describeSpec('Listens:', [], () => {
754754
);
755755

756756
specTest(
757-
'Query is re-listened to after primary tab failover',
757+
'Listen is re-listened to after primary tab failover',
758758
['multi-client'],
759759
() => {
760760
const query = Query.atPath(path('collection'));
@@ -787,13 +787,13 @@ describeSpec('Listens:', [], () => {
787787
}
788788
);
789789

790-
specTest('Query is established in new primary tab', ['multi-client'], () => {
790+
specTest('Listen is established in new primary tab', ['multi-client'], () => {
791791
const query = Query.atPath(path('collection'));
792792
const docA = doc('collection/a', 1000, { key: 'a' });
793793
const docB = doc('collection/b', 2000, { key: 'b' });
794794

795-
// Client 1 and Client 3 listen to the same query. When client 1 shuts
796-
// down, client 2 becomes primary and takes ownership of a query it
795+
// Client 0 and Client 2 listen to the same query. When client 0 shuts
796+
// down, client 1 becomes primary and takes ownership of a query it
797797
// did not previously listen to.
798798
return client(0)
799799
.expectPrimaryState(true)
@@ -814,4 +814,36 @@ describeSpec('Listens:', [], () => {
814814
.client(2)
815815
.expectEvents(query, { added: [docB] });
816816
});
817+
818+
specTest(
819+
'Listen is established in newly started primary',
820+
['multi-client'],
821+
() => {
822+
const query = Query.atPath(path('collection'));
823+
const docA = doc('collection/a', 1000, { key: 'a' });
824+
const docB = doc('collection/b', 2000, { key: 'b' });
825+
826+
// Client 0 executes a query on behalf of Client 1. When client 0 shuts
827+
// down, client 2 starts up and becomes primary, taking ownership of the
828+
// existing query.
829+
return client(0)
830+
.expectPrimaryState(true)
831+
.client(1)
832+
.userListens(query)
833+
.expectEvents(query, { fromCache: true })
834+
.client(0)
835+
.expectListen(query)
836+
.watchAcksFull(query, 1000, docA)
837+
.client(1)
838+
.expectEvents(query, { added: [docA] })
839+
.client(0)
840+
.shutdown()
841+
.client(2)
842+
.expectPrimaryState(true)
843+
.expectListen(query, 'resume-token-1000')
844+
.watchAcksFull(query, 2000, docB)
845+
.client(1)
846+
.expectEvents(query, { added: [docB] });
847+
}
848+
);
817849
});

packages/firestore/test/unit/specs/write_spec.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,4 +1127,22 @@ describeSpec('Writes:', [], () => {
11271127
hasPendingWrites: true
11281128
});
11291129
});
1130+
1131+
specTest('Write is sent by newly started primary', ['multi-client'], () => {
1132+
return client(0)
1133+
.expectPrimaryState(true)
1134+
.client(1)
1135+
.expectPrimaryState(false)
1136+
.userSets('collection/a', { v: 1 })
1137+
.client(0)
1138+
.shutdown()
1139+
.client(2)
1140+
.expectPrimaryState(true)
1141+
.expectNumOutstandingWrites(1)
1142+
.writeAcks('collection/a', 1000, { expectUserCallback: false })
1143+
.client(1)
1144+
.expectUserCallbacks({
1145+
acknowledged: ['collection/a']
1146+
});
1147+
});
11301148
});

0 commit comments

Comments
 (0)