Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
Tests for RequestUtil.shouldListObject and other tests updated to use…
Browse files Browse the repository at this point in the history
… previousFetchTime
  • Loading branch information
AlexeyBarabash committed Jan 3, 2020
1 parent 0c1a818 commit 9c3c937
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions test/client/deviceIdV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ test('deviceId V2 migration', (t) => {
const testCanListFromOldQueue = (t) => {
t.test('can list notification from old SQS queue', (t) => {
let currentTime = new Date().getTime()
requestUtil.list(proto.categories.BOOKMARKS, currentTime)
requestUtil.list(proto.categories.BOOKMARKS, currentTime, 0, '', currentTime)
.then(s3Objects => requestUtil.s3ObjectsToRecords(s3Objects.contents))
.then((response) => {
t.equals(response.length, 1)
Expand Down Expand Up @@ -127,7 +127,7 @@ test('deviceId V2 migration', (t) => {
const testCanListFromBothQueues = (t) => {
t.test('can list notifications from new and old SQS queues', (t) => {
let currentTime = new Date().getTime()
requestUtil.list(proto.categories.BOOKMARKS, currentTime)
requestUtil.list(proto.categories.BOOKMARKS, currentTime, 0, '', currentTime)
.then(s3Objects => requestUtil.s3ObjectsToRecords(s3Objects.contents))
.then((response) => {
t.equals(response.length, 1)
Expand Down
26 changes: 22 additions & 4 deletions test/client/requestUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,25 @@ test('client RequestUtil', (t) => {
})
const serializer = requestUtil.serializer

t.plan(2)
t.plan(3)

t.test('#should list object', (t) => {
t.plan(3)

t.equals(true,
requestUtil.shouldListObject(0, proto.categories.BOOKMARKS),
`${t.name}: previous fetch time is empty - use S3`)

t.equals(false,
requestUtil.shouldListObject(new Date().getTime()-1000*60, proto.categories.BOOKMARKS),
`${t.name}: previous fetch is not older than 24h - use SQS`)

const delta25hours = 1000*60*60*25
t.equals(true,
requestUtil.shouldListObject(new Date().getTime()-delta25hours, proto.categories.BOOKMARKS),
`${t.name}: previous fetch is older than 24h - use S3`)
})

t.test('#put preference: device', (t) => {
t.plan(2)
const deviceId = new Uint8Array([0])
Expand Down Expand Up @@ -288,7 +306,7 @@ test('client RequestUtil', (t) => {
const testCanListNotifications = (t) => {
t.test(`${t.name} can list notification`, (t) => {
let currentTime = new Date().getTime()
requestUtil.list(proto.categories.BOOKMARKS, currentTime)
requestUtil.list(proto.categories.BOOKMARKS, currentTime, 1000, '', currentTime)
.then(s3Objects => requestUtil.s3ObjectsToRecords(s3Objects.contents))
.then((response) => {
const s3Record = response[1] ? response[1].record : response[1]
Expand Down Expand Up @@ -461,7 +479,7 @@ test('client RequestUtil', (t) => {
}
// limit batch size to 10 to test cross batch compaction for around 40
// objects
requestUtil.list(proto.categories.BOOKMARKS, 0, 10, '', {compaction: true,
requestUtil.list(proto.categories.BOOKMARKS, 0, 10, '', 0, {compaction: true,
compactionUpdateCb: compactionUpdate,
compactionDoneCb: () => {
console.log = consoleLogBak
Expand All @@ -474,7 +492,7 @@ test('client RequestUtil', (t) => {
compactedRecord.filter(record => record.objectId.toString() === record2_update.objectId.toString()).length, 5)
// we already have 15 second timeout for each batch so no need to
// do another wait after compaction is done
requestUtil.list(proto.categories.BOOKMARKS, 0, 0)
requestUtil.list(proto.categories.BOOKMARKS, 0, 0, '', 0)
.then(s3Objects => requestUtil.s3ObjectsToRecords(s3Objects.contents))
.then((response) => {
t.equals(response.length, 2, `${t.name} check records number`)
Expand Down

0 comments on commit 9c3c937

Please sign in to comment.