-
Notifications
You must be signed in to change notification settings - Fork 27
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
fix: issue with first variation having weight of 0 #273
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
description: Testing two variations with first one having weight of 0 | ||
tags: | ||
- checkout | ||
|
||
bucketBy: userId | ||
|
||
variations: | ||
- value: control | ||
weight: 0 | ||
|
||
- value: treatment | ||
weight: 100 | ||
|
||
environments: | ||
staging: | ||
rules: | ||
- key: "1" | ||
segments: "*" | ||
percentage: 100 | ||
production: | ||
rules: | ||
- key: "1" | ||
segments: germany | ||
percentage: 100 | ||
- key: "2" | ||
segments: "*" | ||
percentage: 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
feature: pricing | ||
assertions: | ||
- at: 5 | ||
environment: staging | ||
context: | ||
country: nl | ||
expectedToBeEnabled: true | ||
expectedVariation: treatment | ||
|
||
- at: 10 | ||
environment: production | ||
context: | ||
country: nl | ||
expectedToBeEnabled: false | ||
|
||
- at: 20 | ||
environment: production | ||
context: | ||
country: de | ||
expectedToBeEnabled: true | ||
expectedVariation: treatment | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ export function getUpdatedAvailableRangesAfterFilling( | |
availableRanges: Range[], | ||
fill: Percentage, | ||
): Range[] { | ||
if (fill === 0) { | ||
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. this was the fix. this. this little |
||
return availableRanges; | ||
} | ||
|
||
const result: Range[] = []; | ||
|
||
let remaining = fill; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,265 @@ describe("core: Traffic", function () { | |
]); | ||
}); | ||
|
||
it("should allocate traffic for 0-100 weight on two variations", function () { | ||
const result = getTraffic( | ||
// parsed variations from YAML | ||
[ | ||
{ | ||
value: "control", | ||
weight: 0, | ||
}, | ||
{ | ||
value: "treatment", | ||
weight: 100, | ||
}, | ||
], | ||
|
||
// parsed rollouts from YAML | ||
[ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 80, | ||
}, | ||
], | ||
|
||
// existing feature from previous release | ||
undefined, | ||
); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 80000, | ||
allocation: [ | ||
// should be filtered out automatically | ||
// { | ||
// variation: "control", | ||
// range: [0, 0], | ||
// }, | ||
|
||
{ | ||
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. this is failing. the 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. now fixed. |
||
variation: "treatment", | ||
range: [0, 80000], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it("should allocate traffic for 0-100 weight on two variations, with rule percentage going from 80% to 100%", function () { | ||
const result = getTraffic( | ||
// parsed variations from YAML | ||
[ | ||
{ | ||
value: "control", | ||
weight: 0, | ||
}, | ||
{ | ||
value: "treatment", | ||
weight: 100, | ||
}, | ||
], | ||
|
||
// parsed rollouts from YAML | ||
[ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 100, | ||
}, | ||
], | ||
|
||
// existing feature from previous release | ||
{ | ||
variations: [ | ||
{ | ||
value: "control", | ||
weight: 0, | ||
}, | ||
{ | ||
value: "treatment", | ||
weight: 80, | ||
}, | ||
], | ||
traffic: [ | ||
{ | ||
key: "1", | ||
percentage: 80000, | ||
allocation: [ | ||
{ | ||
variation: "treatment", | ||
range: [0, 80000], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 100000, | ||
allocation: [ | ||
// should be filtered out automatically | ||
// { | ||
// variation: "control", | ||
// range: [0, 0], | ||
// }, | ||
|
||
{ | ||
variation: "treatment", | ||
range: [0, 100000], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it("should allocate traffic for 0-100 weight on two variations, with rule percentage going from 100% to 80%", function () { | ||
const result = getTraffic( | ||
// parsed variations from YAML | ||
[ | ||
{ | ||
value: "control", | ||
weight: 0, | ||
}, | ||
{ | ||
value: "treatment", | ||
weight: 100, | ||
}, | ||
], | ||
|
||
// parsed rollouts from YAML | ||
[ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 80, | ||
}, | ||
], | ||
|
||
// existing feature from previous release | ||
{ | ||
variations: [ | ||
{ | ||
value: "control", | ||
weight: 0, | ||
}, | ||
{ | ||
value: "treatment", | ||
weight: 80, | ||
}, | ||
], | ||
traffic: [ | ||
{ | ||
key: "1", | ||
percentage: 100000, | ||
allocation: [ | ||
{ | ||
variation: "treatment", | ||
range: [0, 100000], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 80000, | ||
allocation: [ | ||
// should be filtered out automatically | ||
// { | ||
// variation: "control", | ||
// range: [0, 0], | ||
// }, | ||
|
||
{ | ||
variation: "treatment", | ||
range: [0, 80000], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it("should allocate traffic for existing variations state of 0-100 weights", function () { | ||
const result = getTraffic( | ||
// parsed variations from YAML | ||
[ | ||
{ | ||
value: "control", | ||
weight: 50, | ||
}, | ||
{ | ||
value: "treatment", | ||
weight: 50, | ||
}, | ||
], | ||
|
||
// parsed rollouts from YAML | ||
[ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 80, | ||
}, | ||
], | ||
|
||
// existing feature from previous release | ||
{ | ||
variations: [ | ||
{ | ||
value: "control", | ||
weight: 0, | ||
}, | ||
{ | ||
value: "treatment", | ||
weight: 80, | ||
}, | ||
], | ||
traffic: [ | ||
{ | ||
key: "1", | ||
percentage: 80000, | ||
allocation: [ | ||
{ | ||
variation: "treatment", | ||
range: [0, 80000], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
key: "1", | ||
segments: "*", | ||
percentage: 80000, | ||
allocation: [ | ||
{ | ||
variation: "control", | ||
range: [0, 40000], | ||
}, | ||
{ | ||
variation: "treatment", | ||
range: [40000, 80000], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it("should allocate traffic for 50-50 weight on two variations", function () { | ||
const result = getTraffic( | ||
// parsed variations from YAML | ||
|
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.
this is failing.
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.
now fixed.