Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[AUTOMATED]: Prettier Code Styling
  • Loading branch information
Greg Soltis committed Aug 17, 2018
commit 3c81bce1139df41e89de76e320615f632f74573b
178 changes: 97 additions & 81 deletions packages/firestore/test/unit/specs/offline_spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,49 @@ import { spec } from './spec_builder';
import { TimerId } from '../../../src/util/async_queue';

describeSpec('Offline:', [], () => {
specTest('Empty queries are resolved if client goes offline', ['no-android', 'no-ios'], () => {
const query = Query.atPath(path('collection'));
return (
spec()
.userListens(query)
.watchStreamCloses(Code.UNAVAILABLE)
.expectEvents(query, {
fromCache: true,
hasPendingWrites: false
})
// no further events
.watchStreamCloses(Code.UNAVAILABLE)
.watchStreamCloses(Code.UNAVAILABLE)
);
});
specTest(
'Empty queries are resolved if client goes offline',
['no-android', 'no-ios'],
() => {
const query = Query.atPath(path('collection'));
return (
spec()
.userListens(query)
.watchStreamCloses(Code.UNAVAILABLE)
.expectEvents(query, {
fromCache: true,
hasPendingWrites: false
})
// no further events
.watchStreamCloses(Code.UNAVAILABLE)
.watchStreamCloses(Code.UNAVAILABLE)
);
}
);

specTest('A successful message delays offline status', ['no-android', 'no-ios'], () => {
const query = Query.atPath(path('collection'));
return (
spec()
.userListens(query)
.watchAcks(query)
// first error triggers unknown state
.watchStreamCloses(Code.UNAVAILABLE)
// second error triggers offline state
.watchStreamCloses(Code.UNAVAILABLE)
.expectEvents(query, {
fromCache: true,
hasPendingWrites: false
})
// no further events
.watchStreamCloses(Code.UNAVAILABLE)
.watchStreamCloses(Code.UNAVAILABLE)
);
});
specTest(
'A successful message delays offline status',
['no-android', 'no-ios'],
() => {
const query = Query.atPath(path('collection'));
return (
spec()
.userListens(query)
.watchAcks(query)
// first error triggers unknown state
.watchStreamCloses(Code.UNAVAILABLE)
// second error triggers offline state
.watchStreamCloses(Code.UNAVAILABLE)
.expectEvents(query, {
fromCache: true,
hasPendingWrites: false
})
// no further events
.watchStreamCloses(Code.UNAVAILABLE)
.watchStreamCloses(Code.UNAVAILABLE)
);
}
);

specTest(
'Removing all listeners delays "Offline" status on next listen',
Expand Down Expand Up @@ -91,54 +99,62 @@ describeSpec('Offline:', [], () => {
}
);

specTest('Queries revert to fromCache=true when offline.', ['no-android', 'no-ios'], () => {
const query = Query.atPath(path('collection'));
const docA = doc('collection/a', 1000, { key: 'a' });
return (
spec()
.userListens(query)
.watchAcksFull(query, 1000, docA)
.expectEvents(query, { added: [docA] })
// first error triggers unknown state
.watchStreamCloses(Code.UNAVAILABLE)
.restoreListen(query, 'resume-token-1000')
// second error triggers offline state and fromCache: true
.watchStreamCloses(Code.UNAVAILABLE)
.expectEvents(query, { fromCache: true })
// Going online and getting a CURRENT message triggers fromCache: false
.watchAcksFull(query, 1000)
.expectEvents(query, { fromCache: false })
);
});
specTest(
'Queries revert to fromCache=true when offline.',
['no-android', 'no-ios'],
() => {
const query = Query.atPath(path('collection'));
const docA = doc('collection/a', 1000, { key: 'a' });
return (
spec()
.userListens(query)
.watchAcksFull(query, 1000, docA)
.expectEvents(query, { added: [docA] })
// first error triggers unknown state
.watchStreamCloses(Code.UNAVAILABLE)
.restoreListen(query, 'resume-token-1000')
// second error triggers offline state and fromCache: true
.watchStreamCloses(Code.UNAVAILABLE)
.expectEvents(query, { fromCache: true })
// Going online and getting a CURRENT message triggers fromCache: false
.watchAcksFull(query, 1000)
.expectEvents(query, { fromCache: false })
);
}
);

specTest('Queries with limbo documents handle going offline.', ['no-android', 'no-ios'], () => {
const query = Query.atPath(path('collection'));
const docA = doc('collection/a', 1000, { key: 'a' });
const limboQuery = Query.atPath(docA.key.path);
return (
spec()
.userListens(query)
.watchAcksFull(query, 1000, docA)
.expectEvents(query, { added: [docA] })
.watchResets(query)
// No more documents
.watchCurrents(query, 'resume-token-1001')
.watchSnapshots(1001)
// docA will now be in limbo (triggering fromCache=true)
.expectLimboDocs(docA.key)
.expectEvents(query, { fromCache: true })
// first error triggers unknown state
.watchStreamCloses(Code.UNAVAILABLE)
.restoreListen(query, 'resume-token-1001')
// second error triggers offline state.
.watchStreamCloses(Code.UNAVAILABLE)
.watchAcksFull(query, 1001)
.watchAcksFull(limboQuery, 1001)
// Limbo document is resolved. No longer from cache.
.expectEvents(query, { removed: [docA], fromCache: false })
.expectLimboDocs()
);
});
specTest(
'Queries with limbo documents handle going offline.',
['no-android', 'no-ios'],
() => {
const query = Query.atPath(path('collection'));
const docA = doc('collection/a', 1000, { key: 'a' });
const limboQuery = Query.atPath(docA.key.path);
return (
spec()
.userListens(query)
.watchAcksFull(query, 1000, docA)
.expectEvents(query, { added: [docA] })
.watchResets(query)
// No more documents
.watchCurrents(query, 'resume-token-1001')
.watchSnapshots(1001)
// docA will now be in limbo (triggering fromCache=true)
.expectLimboDocs(docA.key)
.expectEvents(query, { fromCache: true })
// first error triggers unknown state
.watchStreamCloses(Code.UNAVAILABLE)
.restoreListen(query, 'resume-token-1001')
// second error triggers offline state.
.watchStreamCloses(Code.UNAVAILABLE)
.watchAcksFull(query, 1001)
.watchAcksFull(limboQuery, 1001)
// Limbo document is resolved. No longer from cache.
.expectEvents(query, { removed: [docA], fromCache: false })
.expectLimboDocs()
);
}
);

specTest('OnlineState timeout triggers offline behavior', [], () => {
const query = Query.atPath(path('collection'));
Expand Down