mirror of https://github.com/coder/coder.git
chore(pty/ptytest): add sync.Once to close (#10220)
This commit is contained in:
parent
ac623b4717
commit
98a076fb46
|
@ -350,22 +350,28 @@ func (e *outExpecter) fatalf(reason string, format string, args ...interface{})
|
|||
type PTY struct {
|
||||
outExpecter
|
||||
pty.PTY
|
||||
closeOnce sync.Once
|
||||
closeErr error
|
||||
}
|
||||
|
||||
func (p *PTY) Close() error {
|
||||
p.t.Helper()
|
||||
pErr := p.PTY.Close()
|
||||
if pErr != nil {
|
||||
p.logf("PTY: Close failed: %v", pErr)
|
||||
}
|
||||
eErr := p.outExpecter.close("PTY close")
|
||||
if eErr != nil {
|
||||
p.logf("PTY: close expecter failed: %v", eErr)
|
||||
}
|
||||
if pErr != nil {
|
||||
return pErr
|
||||
}
|
||||
return eErr
|
||||
p.closeOnce.Do(func() {
|
||||
pErr := p.PTY.Close()
|
||||
if pErr != nil {
|
||||
p.logf("PTY: Close failed: %v", pErr)
|
||||
}
|
||||
eErr := p.outExpecter.close("PTY close")
|
||||
if eErr != nil {
|
||||
p.logf("PTY: close expecter failed: %v", eErr)
|
||||
}
|
||||
if pErr != nil {
|
||||
p.closeErr = pErr
|
||||
return
|
||||
}
|
||||
p.closeErr = eErr
|
||||
})
|
||||
return p.closeErr
|
||||
}
|
||||
|
||||
func (p *PTY) Attach(inv *clibase.Invocation) *PTY {
|
||||
|
|
Loading…
Reference in New Issue