Skip to content

Commit

Permalink
Fixing a bug in init ingestion
Browse files Browse the repository at this point in the history
  • Loading branch information
airdeploy-eng committed Feb 26, 2021
1 parent 0de0796 commit 95110dc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flagger",
"version": "3.0.15",
"version": "3.0.16",
"description": "An open source JavaScript SDK for feature flagging (feature gating, feature toggles) for Node.js and Javascript applications",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down
6 changes: 2 additions & 4 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ describe('init function tests', () => {

await Flagger.init({
apiKey,
sseURL,
logLevel: LogLevel.debug
sseURL
})
await Flagger.init({
apiKey,
sseURL,
logLevel: LogLevel.error
sseURL
})

await Flagger.shutdown()
Expand Down
8 changes: 8 additions & 0 deletions src/ingester/strategy/groupStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class GroupStrategy implements IIngestionStrategy {
private detectedFlags: Set<string> = new Set()
private readonly sendDataFunction: (url: string, data: any) => Promise<any>
private ingestionPromise?: Promise<void>
private isInitIngestionSent = false

constructor({
ingestionURL,
Expand Down Expand Up @@ -152,6 +153,13 @@ export default class GroupStrategy implements IIngestionStrategy {
}

private async sendData(reason: string) {
if (this.isEmpty()) {
if (this.isInitIngestionSent) {
return
} else {
this.isInitIngestionSent = true
}
}
logger.debug(`${reason} triggers ingestion request`)

const requestBody = {
Expand Down
20 changes: 20 additions & 0 deletions src/ingestion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,26 @@ describe('ingestion plugin data test', () => {
const errors = ajv.errorsText(ingestionValidator.errors)
expect(errors).toEqual('No errors')
})
it('browser must not send more than 1 empty ingestion upon init', async () => {
const trackCallback = jest.fn()
api
.post(uri)
.optionally()
.reply(200, (_, body: any) => {
trackCallback(body)
})

await Flagger.init({
apiKey,
sdkInfo: {name: JS_SDK_NAME, version},
sseURL
})

await waitTime(1000)

expect(trackCallback).toHaveBeenCalledTimes(1)
await Flagger.shutdown()
})
})

describe('Nodejs tests', () => {
Expand Down

0 comments on commit 95110dc

Please sign in to comment.