Skip to content

Commit

Permalink
fix: fixed bug with rollout when starting with 100 instead of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalaber committed Dec 2, 2024
1 parent 173a123 commit 10b9833
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion lib/shared/bucketing/__tests__/bucketing.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-len */
import { Audience, FeatureType, Rollout } from '@devcycle/types'
import { Audience, FeatureType, PublicRollout, Rollout } from '@devcycle/types'
import {
generateBoundedHashes,
decideTargetVariation,
Expand Down Expand Up @@ -1415,6 +1415,43 @@ describe('Rollout Logic', () => {
doesUserPassRollout({ rollout, boundedHash: 0.9 }),
).toBeFalsy()
})

it('should handle stepped rollout with 100% start and 0% later stage', () => {
const rollout: PublicRollout = {
type: 'stepped',
startDate: new Date(),
startPercentage: 1,
stages: [
{
type: 'discrete',
date: new Date(
new Date().getTime() + 1000 * 60 * 60 * 24 * 7,
),
percentage: 0,
},
],
}

// Before next stage - should be 100%
jest.useFakeTimers().setSystemTime(new Date())
for (let i = 0; i < 100; i++) {
expect(
doesUserPassRollout({ rollout, boundedHash: i / 100 }),
).toBeTruthy()
}

// After 0% stage - should fail all users
jest.useFakeTimers().setSystemTime(
new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 8),
)
for (let i = 0; i < 100; i++) {
expect(
doesUserPassRollout({ rollout, boundedHash: i / 100 }),
).toBeFalsy()
}

jest.useRealTimers()
})
})

it('throws when given an empty rollout object', () => {
Expand Down

0 comments on commit 10b9833

Please sign in to comment.