Created
April 23, 2024 08:08
-
-
Save gastonfournier/c20a1b57df3af69c7590c37c0dd2a037 to your computer and use it in GitHub Desktop.
Unleash roll up&down consistency test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you can run unleash locally with https://docs.getunleash.io/quickstart#i-want-to-run-unleash-locally | |
// create a toggle named flag-1 and add the rollout strategy sticky on userId | |
// then play around rolling up and down. | |
// Note: to run this you'll need to have an npm project (npm init) and add unleash dependency (npm i unleash-client) | |
import { initialize } from 'unleash-client'; | |
const unleash = initialize({ | |
url: 'http://localhost:4242', | |
appName: 'my-node-name', | |
refreshInterval: 200, | |
environment: 'development', | |
customHeaders: { Authorization: 'default:development.xxx' }, | |
instanceId: 'my-unique-instance-id', | |
}); | |
let done = false; | |
function checkFlags() { | |
const flag = 'flag-1'; | |
const flagResults = {}; | |
for (let i = 0; i < 10; i++) { | |
const userId = `user-${i}`; | |
const enabled = unleash.isEnabled(flag, { | |
userId: `213${i}`, | |
currentTime: new Date().getTime(), | |
}, false); | |
flagResults[userId] = enabled; | |
} | |
let log = ""; | |
for (const userId in flagResults) { | |
log += `${userId}\t`; | |
} | |
log += `\n`; | |
for (const userId in flagResults) { | |
log += `${flagResults[userId]}\t`; | |
} | |
console.log(log); | |
// set a timeout to execute this function again | |
if (!done) { | |
setTimeout(checkFlags, 1000); | |
} | |
} | |
unleash.on('ready', async () => { | |
checkFlags(); | |
}); | |
process.on('SIGINT', () => { | |
done = true; | |
unleash.destroy(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment