test/e2e: optimize RunFrps/RunFrpc with process exit detection (#5225)

* test/e2e: optimize RunFrps/RunFrpc with process exit detection

Refactor Process to track subprocess lifecycle via a done channel,
replacing direct cmd.Wait() in Stop() to avoid double-Wait races.
RunFrps/RunFrpc now use select on the done channel instead of fixed
sleeps, allowing short-lived processes (verify, startup failures) to
return immediately while preserving existing timeout behavior for
long-running daemons.

* test/e2e: guard Process against double-Start and Stop-before-Start

Add started flag to prevent double-Start panics and allow Stop to
return immediately when the process was never started. Use sync.Once
for closing the done channel as defense-in-depth against double close.
This commit is contained in:
fatedier
2026-03-09 10:28:47 +08:00
committed by GitHub
parent bcd2424c24
commit 48e8901466
2 changed files with 44 additions and 5 deletions

View File

@@ -76,7 +76,10 @@ func (f *Framework) RunFrps(args ...string) (*process.Process, string, error) {
if err != nil {
return p, p.Output(), err
}
time.Sleep(2 * time.Second)
select {
case <-p.Done():
case <-time.After(2 * time.Second):
}
return p, p.Output(), nil
}
@@ -87,7 +90,10 @@ func (f *Framework) RunFrpc(args ...string) (*process.Process, string, error) {
if err != nil {
return p, p.Output(), err
}
time.Sleep(1500 * time.Millisecond)
select {
case <-p.Done():
case <-time.After(1500 * time.Millisecond):
}
return p, p.Output(), nil
}