Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
2tefan committed Oct 10, 2023
1 parent 49b53fc commit d84a744
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
1 change: 0 additions & 1 deletion readAndExecute.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ func execCmd(command *command, received *receivedStruct, result *answer, config

// https://github.com/golang/go/issues/18874
// timeout does not work for child processes and/or if file handles are still open
// TODO: This could be the source of the zombies (go keyword)
go func(proc *os.Process) {
defer logPanicExit()
<-ctx.Done() // wait till command runs into timeout or is finished (canceled)
Expand Down
30 changes: 1 addition & 29 deletions readAndExecute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,37 +198,9 @@ func TestExecuteCommandWithTimeoutII(t *testing.T) {
config.timeoutReturn = 3
result = &answer{}

//executeCommandLine(result, &receivedStruct{commandLine: `sleep 30`, timeout: 50}, &config)
//executeCommandLine(result, &receivedStruct{commandLine: `python3 /tmp/python-test-d.py`, timeout: 5}, &config)
//executeCommandLine(result, &receivedStruct{commandLine: `(sleep 30 &)`, timeout: 5}, &config)
//executeCommandLine(result, &receivedStruct{commandLine: `python3 -c "import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind(('localhost', 50000)); s.listen(1); fd, addr = s.accept();"`, timeout: 25}, &config)
//executeCommandLine(result, &receivedStruct{commandLine: `python3 -c "import subprocess; import socket; p = subprocess.Popen('sleep 600', stdout=subprocess.PIPE, shell=True); p.kill(); s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind(('localhost', 50000)); s.listen(1); fd, addr = s.accept();"`, timeout: 4}, &config)
//executeCommandLine(result, &receivedStruct{commandLine: `python3 -c "import subprocess; import socket; p = subprocess.Popen(['/bin/python2.7', '-c' ,'\"import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind((\'localhost\', 50001)); s.listen(1); fd, addr = s.accept();\"'], stdout=subprocess.PIPE, shell=False); p.kill(); s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind(('localhost', 50000)); s.listen(1); fd, addr = s.accept();"`, timeout: 3}, &config)
//executeCommandLine(result, &receivedStruct{commandLine: `nohup python3 -c "import subprocess; import socket; p = subprocess.Popen(['/bin/python2.7', '-c' ,'\"import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind((\'localhost\', 50001)); s.listen(1); fd, addr = s.accept();\"'], stdout=subprocess.PIPE, shell=False); p.kill(); s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind(('localhost', 50000)); s.listen(1); fd, addr = s.accept();" &`, timeout: 3}, &config)
//executeCommandLine(result, &receivedStruct{commandLine: `nohup python3 -c "import subprocess; import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind(('localhost', 50000)); s.listen(1); fd, addr = s.accept();"`, timeout: 3}, &config)
//executeCommandLine(result, &receivedStruct{commandLine: `bash -c "(nohup python3 -c "import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind(('localhost', 50000)); s.listen(1); fd, addr = s.accept(); &) ; disown -a"`, timeout: 3}, &config)
// Spawning a daemon process
executeCommandLine(result, &receivedStruct{commandLine: `python3 test/python-daemon.py`, timeout: 3}, &config)

// func1 := func() {
// }
// func2 := func() {
// executeCommandLine(result, &receivedStruct{commandLine: `python3 -c "import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind(('localhost', 50000)); s.listen(1); fd, addr = s.accept();""`, timeout: 10}, &config)
// }
// func3 := func() {
// executeCommandLine(result, &receivedStruct{commandLine: `python3 -c "import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.bind(('localhost', 50000)); s.listen(1); fd, addr = s.accept();"`, timeout: 10}, &config)
// }
// func4 := func() {
// executeCommandLine(result, &receivedStruct{commandLine: `trap 'echo Booh!' SIGINT SIGTERM; sleep 2"`, timeout: 10}, &config)
// }
// func5 := func() {
// executeCommandLine(result, &receivedStruct{commandLine: `/bin/sh -c \"trap 'echo Booh!' SIGINT SIGTERM; sleep 2\"`, timeout: 10}, &config)
// }
// func6 := func() {
// executeCommandLine(result, &receivedStruct{commandLine: `python2.7 -c "echo hi"`, timeout: 10}, &config)
// }

//Parallelize(func1,func2,func3,func4,func5,func6)

if !strings.HasPrefix(result.output, "(Check Timed Out On Worker:") || result.returnCode != 3 {
t.Errorf("got %s, with code: %d but expected: %s and code: %d", result.output, result.returnCode, "timeout", 3)
}
Expand Down

0 comments on commit d84a744

Please sign in to comment.