-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
Rebuild Config on Server Restart #2076
Rebuild Config on Server Restart #2076
Conversation
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 probably important to test.
Here's a potential path forward:
- set a config with an ENV (like PORT=12345)
- startup the test like normal
actionhero/__tests__/actions/cacheTest.ts
Lines 5 to 7 in 80895af
const actionhero = new Process(); beforeAll(async () => await actionhero.start()); afterAll(async () => await actionhero.stop()); - test that the config is what you expect (config.web.port === 12345)
- change the ENV in the test
- assert that the config is the old value
- reboot the server (process.restart)
- assert that the config is the new value
it("updates config on 'restart'", () => { | ||
const port = "2020"; | ||
process.env.PORT = port; | ||
expect(config.web.port).not.toBe(port); | ||
rebuildConfig(); | ||
expect(config.web.port).toBe(port); | ||
}); |
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.
👍
export let config = buildConfig(); | ||
export const rebuildConfig = () => { | ||
recalculateEnv(); | ||
recalculateActionheroVersion(); | ||
recalcuateId(); | ||
recalculateProjectRoot(); | ||
recalculateIsTypescript(); | ||
config = buildConfig(); | ||
}; |
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 a great pattern!
Adding rebuild config method. Calling rebuild config method on server restart.