Skip to content

Commit

Permalink
rename startingWeightPerServer to maxWeightPerServer
Browse files Browse the repository at this point in the history
  • Loading branch information
jodevsa committed Jul 9, 2022
1 parent a05c547 commit 467f847
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BalancedPool extends PoolBase {
this[kIndex] = -1
this[kCurrentWeight] = 0

this[kMaxWeightPerServer] = this[kOptions].startingWeightPerServer || 100
this[kMaxWeightPerServer] = this[kOptions].maxWeightPerServer || 100
this[kErrorPenalty] = this[kOptions].errorPenalty || 15

if (!Array.isArray(upstreams)) {
Expand Down
24 changes: 12 additions & 12 deletions test/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 7,
config: [{ server: 'A' }, { server: 'B' }, { server: 'C' }],
expected: ['A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C'],
Expand All @@ -349,7 +349,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A', downOnRequests: [0] }, { server: 'B' }, { server: 'C' }],
expected: ['A/connectionRefused', 'B', 'C', 'B', 'C', 'B', 'C', 'A', 'B', 'C', 'A'],
Expand All @@ -362,7 +362,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A' }, { server: 'B', downOnRequests: [0] }, { server: 'C' }],
expected: ['A', 'B/connectionRefused', 'C', 'A', 'C', 'A', 'C', 'A', 'B', 'C'],
Expand All @@ -375,7 +375,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A' }, { server: 'B', downOnRequests: [0] }, { server: 'C', downOnRequests: [0] }],
expected: ['A', 'B/connectionRefused', 'C/connectionRefused', 'A', 'A', 'A', 'B', 'C'],
Expand All @@ -388,7 +388,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A', downOnRequests: [0] }, { server: 'B', downOnRequests: [0] }, { server: 'C', downOnRequests: [0] }],
expected: ['A/connectionRefused', 'B/connectionRefused', 'C/connectionRefused', 'A', 'B', 'C', 'A', 'B', 'C'],
Expand All @@ -401,7 +401,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A', downOnRequests: [0, 1, 2] }, { server: 'B', downOnRequests: [0, 1, 2] }, { server: 'C', downOnRequests: [0, 1, 2] }],
expected: ['A/connectionRefused', 'B/connectionRefused', 'C/connectionRefused', 'A/connectionRefused', 'B/connectionRefused', 'C/connectionRefused', 'A/connectionRefused', 'B/connectionRefused', 'C/connectionRefused', 'A', 'B', 'C', 'A', 'B', 'C'],
Expand All @@ -414,7 +414,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A', downOnRequests: [0] }, { server: 'B', downOnRequests: [0, 1] }, { server: 'C', downOnRequests: [0] }],
expected: ['A/connectionRefused', 'B/connectionRefused', 'C/connectionRefused', 'A', 'B/connectionRefused', 'C', 'A', 'B', 'C', 'A', 'B', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'A', 'B'],
Expand All @@ -427,7 +427,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A' }, { server: 'B' }, { server: 'C', downOnRequests: [1] }],
expected: ['A', 'B', 'C', 'A', 'B', 'C/connectionRefused', 'A', 'B', 'A', 'B', 'A', 'B', 'C', 'A', 'B', 'C'],
Expand All @@ -440,7 +440,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 15,
config: [{ server: 'A', socketHangupOnRequests: [1] }, { server: 'B' }, { server: 'C' }],
expected: ['A', 'B', 'C', 'A/socketError', 'B', 'C', 'B', 'C', 'B', 'C', 'A'],
Expand All @@ -453,7 +453,7 @@ const cases = [

{
iterations: 100,
startingWeightPerServer: 100,
maxWeightPerServer: 100,
errorPenalty: 7,
config: [{ server: 'A' }, { server: 'B' }, { server: 'C' }, { server: 'D' }, { server: 'E' }],
expected: ['A', 'B', 'C', 'D', 'E', 'A', 'B', 'C', 'D', 'E'],
Expand All @@ -464,7 +464,7 @@ const cases = [

]

for (const [index, { config, expected, expectedRatios, iterations = 9, expectedConnectionRefusedErrors = 0, expectedSocketErrors = 0, startingWeightPerServer, errorPenalty = 10 }] of cases.entries()) {
for (const [index, { config, expected, expectedRatios, iterations = 9, expectedConnectionRefusedErrors = 0, expectedSocketErrors = 0, maxWeightPerServer, errorPenalty = 10 }] of cases.entries()) {
test(`weighted round robin - case ${index}`, async (t) => {
// cerate an array to store succesfull reqeusts
const requestLog = []
Expand All @@ -485,7 +485,7 @@ for (const [index, { config, expected, expectedRatios, iterations = 9, expectedC
const urls = servers.map(server => `http://localhost:${server.port}`)

// add upstreams
const client = new BalancedPool(urls[0], { startingWeightPerServer, errorPenalty })
const client = new BalancedPool(urls[0], { maxWeightPerServer, errorPenalty })
urls.slice(1).map(url => client.addUpstream(url))

let connectionRefusedErrors = 0
Expand Down

0 comments on commit 467f847

Please sign in to comment.