-
Notifications
You must be signed in to change notification settings - Fork 83
[FSSDK-11003] disposable service implementation #981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
060cbc3
11c850d
17d27a3
e516e39
08d0df4
bad40b4
f2c3b5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,6 +207,40 @@ describe('DefaultOdpEventManager', () => { | |
} | ||
}); | ||
|
||
it('should flush the queue immediately if disposable, regardless of the batchSize', async () => { | ||
const apiManager = getMockApiManager(); | ||
const repeater = getMockRepeater() | ||
apiManager.sendEvents.mockResolvedValue({ statusCode: 200 }); | ||
|
||
const odpEventManager = new DefaultOdpEventManager({ | ||
repeater, | ||
apiManager: apiManager, | ||
batchSize: 10, | ||
retryConfig: { | ||
maxRetries: 3, | ||
backoffProvider: vi.fn(), | ||
}, | ||
}); | ||
|
||
odpEventManager.updateConfig({ | ||
integrated: true, | ||
odpConfig: config, | ||
}); | ||
odpEventManager.makeDisposable(); | ||
odpEventManager.start(); | ||
|
||
await expect(odpEventManager.onRunning()).resolves.not.toThrow(); | ||
|
||
const event = makeEvent(0); | ||
odpEventManager.sendEvent(event); | ||
await exhaustMicrotasks(); | ||
|
||
expect(apiManager.sendEvents).toHaveBeenCalledTimes(1); | ||
expect(apiManager.sendEvents).toHaveBeenNthCalledWith(1, config, [event]); | ||
expect(repeater.reset).toHaveBeenCalledTimes(1); | ||
expect(repeater.start).not.toHaveBeenCalled(); | ||
}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also add tests for repeater stop when disposable = true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the actual implementation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see we have assertions for repeater.reset here. We can ignore this comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can add a test to assert the repeater is not started, similar to eventProcessor |
||
it('drops events and logs if the state is not running', async () => { | ||
const apiManager = getMockApiManager(); | ||
apiManager.sendEvents.mockResolvedValue({ statusCode: 200 }); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ const getMockOdpEventManager = () => { | |
getState: vi.fn(), | ||
updateConfig: vi.fn(), | ||
sendEvent: vi.fn(), | ||
makeDisposable: vi.fn(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add test that it makes the eventManager disposable when its makeDisposable() is called? |
||
}; | ||
}; | ||
|
||
|
@@ -696,5 +697,19 @@ describe('DefaultOdpManager', () => { | |
eventManagerTerminatedPromise.reject(new Error(FAILED_TO_STOP)); | ||
await expect(odpManager.onTerminated()).rejects.toThrow(); | ||
}); | ||
|
||
it('should call makeDisposable() on eventManager when makeDisposable() is called on odpManager', async () => { | ||
const eventManager = getMockOdpEventManager(); | ||
const segmentManager = getMockOdpSegmentManager(); | ||
|
||
const odpManager = new DefaultOdpManager({ | ||
segmentManager, | ||
eventManager, | ||
}); | ||
|
||
odpManager.makeDisposable(); | ||
|
||
expect(eventManager.makeDisposable).toHaveBeenCalled(); | ||
}) | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add tests for the following as well when disposable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding your number 2 - Current logic is -
dispatchRepeater
starts, dispatch immediately and then stops. Isn't this expected ? Or am I missing something here ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the refactored logic in this PR, if batchSize == 1, dispatch repeater should never start. It will immediately dispatch the event, the repeater start is in the else branch