MCPcopy Index your code
hub / github.com/coder/coder / TestSignalProcess

Function TestSignalProcess

agent/agentproc/api_test.go:947–1076  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

945}
946
947func TestSignalProcess(t *testing.T) {
948 t.Parallel()
949
950 t.Run("KillRunning", func(t *testing.T) {
951 t.Parallel()
952
953 handler := newTestAPI(t)
954
955 id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{
956 Command: "sleep 300",
957 Background: true,
958 })
959
960 w := postSignal(t, handler, id, workspacesdk.SignalProcessRequest{
961 Signal: "kill",
962 })
963 require.Equal(t, http.StatusOK, w.Code)
964
965 // Verify the process exits.
966 resp := waitForExit(t, handler, id)
967 require.False(t, resp.Running)
968 })
969
970 t.Run("TerminateRunning", func(t *testing.T) {
971 t.Parallel()
972
973 if runtime.GOOS == "windows" {
974 t.Skip("SIGTERM is not supported on Windows")
975 }
976
977 handler := newTestAPI(t)
978
979 id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{
980 Command: "sleep 300",
981 Background: true,
982 })
983
984 w := postSignal(t, handler, id, workspacesdk.SignalProcessRequest{
985 Signal: "terminate",
986 })
987 require.Equal(t, http.StatusOK, w.Code)
988
989 // Verify the process exits.
990 resp := waitForExit(t, handler, id)
991 require.False(t, resp.Running)
992 })
993
994 t.Run("NonexistentProcess", func(t *testing.T) {
995 t.Parallel()
996
997 handler := newTestAPI(t)
998 w := postSignal(t, handler, "nonexistent-id-12345", workspacesdk.SignalProcessRequest{
999 Signal: "kill",
1000 })
1001 require.Equal(t, http.StatusNotFound, w.Code)
1002 })
1003
1004 t.Run("AlreadyExitedProcess", func(t *testing.T) {

Callers

nothing calls this directly

Calls 8

startAndGetIDFunction · 0.85
postSignalFunction · 0.85
waitForExitFunction · 0.85
SkipMethod · 0.80
newTestAPIFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected