Skip to content
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

Add a test mode flag #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions overseer.go
Expand Up @@ -47,6 +47,9 @@ type Config struct {
PreUpgrade func(tempBinaryPath string) error
//Debug enables all [overseer] logs.
Debug bool
//Test disables fork and server restart to make it possible to unit test
//the server.
Test bool
//NoWarn disables warning [overseer] logs.
NoWarn bool
//NoRestart disables all restarts, this option essentially converts
Expand Down
26 changes: 26 additions & 0 deletions proc_master.go
Expand Up @@ -62,6 +62,32 @@ func (mp *master) run() error {
mp.fetch()
go mp.fetchLoop()
}
if mp.Test {
mp.debugf("test mode enabled")
state := State{
Enabled: true,
ID: hex.EncodeToString(mp.binHash),
StartedAt: time.Now(),
Address: mp.Config.Address,
Addresses: mp.Config.Addresses,
GracefulShutdown: make(chan bool, 1),
BinPath: mp.binPath,
}
state.Listeners = make([]net.Listener, len(mp.slaveExtraFiles))
for i, extraFile := range mp.slaveExtraFiles {
l, err := net.FileListener(extraFile)
if err != nil {
return fmt.Errorf("failed to inherit file descriptor: %d", i)
}
u := newOverseerListener(l)
state.Listeners[i] = u
}
if len(state.Listeners) > 0 {
state.Listener = state.Listeners[0]
}
mp.Config.Program(state)
return nil
}
return mp.forkLoop()
}

Expand Down