Skip to content

Commit

Permalink
fix: time resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Aug 15, 2023
1 parent d6309fa commit 36623ad
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 211 deletions.
201 changes: 0 additions & 201 deletions src/streaming-feed.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/streaming-feed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ export class StreamingFeed implements IStreamingFeed<number> {
* @param initialTime initial time of streaming feed
* @param updatePeriod streaming feed frequency in milliseconds
* @param lookupTime lookup time
* @param discover boolean, indicates whether the algorithm will look for the closest successful hit
* @returns a StreamingFeedChunk object
*/
const getUpdate = async (
initialTime: number,
updatePeriod: number,
lookupTime?: number,
discover = true,
): Promise<StreamingFeedChunk> => {
lookupTime = lookupTime ?? getCurrentTime()
const index = getIndexForArbitraryTime(lookupTime, initialTime, updatePeriod)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ export function isObject(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === 'object'
}

export const getCurrentTime = (d = new Date()): number => d.getTime()
export const getCurrentTime = (d = new Date()): number => Math.floor(d.getTime() / 1000) // ms to s
18 changes: 9 additions & 9 deletions test/integration/streaming-feed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('streaming feed', () => {
const feedRw = streamingFeed.makeFeedRW(topic, signer)

const initialTime = getCurrentTime()
const updatePeriod = 5000
const updatePeriod = 5
const testReference: Reference = '0000000000000000000000000000000000000000000000000000000000000126' as HexString<64>
await feedRw.setLastUpdate(batchId, testReference, initialTime, updatePeriod)

Expand All @@ -45,7 +45,7 @@ describe('streaming feed', () => {
const feedRw = streamingFeed.makeFeedRW(topic, signer)

const initialTime = getCurrentTime()
const updatePeriod = 5000
const updatePeriod = 5

const feedUpdate = await feedRw.findLastUpdate(initialTime, updatePeriod)

Expand All @@ -71,7 +71,7 @@ describe('streaming feed', () => {
const random = new Date().getTime().toString().padStart(64, '0')
const multipleUpdateTopic = Utils.Hex.makeHexString(random) as Topic

const updatePeriod = 5000
const updatePeriod = 5
const feedRw = streamingFeed.makeFeedRW(multipleUpdateTopic, signer)

const numUpdates = 5
Expand All @@ -93,11 +93,11 @@ describe('streaming feed', () => {
}

const feedUpdateResponse = await feedRw.getUpdates(initialTime, updatePeriod)
expect(feedUpdateResponse.length).toEqual(5)
expect(feedUpdateResponse[0].updatePeriod).toEqual(5000)
expect(feedUpdateResponse[1].updatePeriod).toEqual(5000)
expect(feedUpdateResponse[2].updatePeriod).toEqual(5000)
expect(feedUpdateResponse[3].updatePeriod).toEqual(5000)
expect(feedUpdateResponse[4].updatePeriod).toEqual(5000)
expect(feedUpdateResponse.length).toEqual(numUpdates)
expect(feedUpdateResponse[0].updatePeriod).toEqual(updatePeriod)
expect(feedUpdateResponse[1].updatePeriod).toEqual(updatePeriod)
expect(feedUpdateResponse[2].updatePeriod).toEqual(updatePeriod)
expect(feedUpdateResponse[3].updatePeriod).toEqual(updatePeriod)
expect(feedUpdateResponse[4].updatePeriod).toEqual(updatePeriod)
}, 45000)
})

0 comments on commit 36623ad

Please sign in to comment.