
When the context passed to Nomad Allocation Exec is cancelled, the process is not terminated. Instead, just the WebSocket connection is closed. In order to terminate long-running processes, a special character is injected into the standard input stream. This character is parsed by the tty line discipline (tty has to be true). The line discipline sends a SIGQUIT signal to the process, terminating it and producing a core dump (in a file called 'core'). The SIGQUIT signal can be caught but isn't by default, which is why the runner is destroyed if the program does not terminate during a grace period after the signal was sent.
32 lines
560 B
Go
32 lines
560 B
Go
package nullio
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
const shortTimeout = 100 * time.Millisecond
|
|
|
|
func TestReaderDoesNotReturnImmediately(t *testing.T) {
|
|
reader := &Reader{}
|
|
readerReturned := make(chan bool)
|
|
go func() {
|
|
p := make([]byte, 0, 5)
|
|
_, err := reader.Read(p)
|
|
require.NoError(t, err)
|
|
close(readerReturned)
|
|
}()
|
|
|
|
var received bool
|
|
select {
|
|
case <-readerReturned:
|
|
received = true
|
|
case <-time.After(shortTimeout):
|
|
received = false
|
|
}
|
|
|
|
assert.False(t, received)
|
|
}
|