-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add recovery tests to zk_supervisor (#2444)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> Add recovery tests to zk_supervisor ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --------- Signed-off-by: Danil <[email protected]> Co-authored-by: Manuel <[email protected]> Co-authored-by: Danil <[email protected]>
- Loading branch information
1 parent
2fa2249
commit 0c0d10a
Showing
15 changed files
with
395 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { spawn as _spawn, ChildProcessWithoutNullStreams, type ProcessEnvOptions } from 'child_process'; | ||
|
||
// executes a command in background and returns a child process handle | ||
// by default pipes data to parent's stdio but this can be overridden | ||
export function background({ | ||
command, | ||
stdio = 'inherit', | ||
cwd, | ||
env | ||
}: { | ||
command: string; | ||
stdio: any; | ||
cwd?: ProcessEnvOptions['cwd']; | ||
env?: ProcessEnvOptions['env']; | ||
}): ChildProcessWithoutNullStreams { | ||
command = command.replace(/\n/g, ' '); | ||
console.log(`Running command in background: ${command}`); | ||
return _spawn(command, { stdio: stdio, shell: true, detached: true, cwd, env }); | ||
} | ||
|
||
export function runInBackground({ | ||
command, | ||
components, | ||
stdio, | ||
cwd, | ||
env | ||
}: { | ||
command: string; | ||
components?: string[]; | ||
stdio: any; | ||
cwd?: Parameters<typeof background>[0]['cwd']; | ||
env?: Parameters<typeof background>[0]['env']; | ||
}): ChildProcessWithoutNullStreams { | ||
if (components && components.length > 0) { | ||
command += ` --components=${components.join(',')}`; | ||
} | ||
|
||
return background({ | ||
command, | ||
stdio, | ||
cwd, | ||
env | ||
}); | ||
} | ||
|
||
export function runExternalNodeInBackground({ | ||
components, | ||
stdio, | ||
cwd, | ||
env, | ||
useZkInception | ||
}: { | ||
components?: string[]; | ||
stdio: any; | ||
cwd?: Parameters<typeof background>[0]['cwd']; | ||
env?: Parameters<typeof background>[0]['env']; | ||
useZkInception?: boolean; | ||
}): ChildProcessWithoutNullStreams { | ||
let command = ''; | ||
if (useZkInception) { | ||
command = 'zk_inception external-node run'; | ||
} else { | ||
command = 'zk external-node --'; | ||
|
||
const enableConsensus = process.env.ENABLE_CONSENSUS === 'true'; | ||
if (enableConsensus) { | ||
command += ' --enable-consensus'; | ||
} | ||
} | ||
return runInBackground({ command, components, stdio, cwd, env }); | ||
} |
This file contains 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
Oops, something went wrong.