diff options
author | zeripath <art27@cantab.net> | 2019-11-30 08:40:22 -0600 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-11-30 16:40:22 +0200 |
commit | 60c5339042a605076482320313e8f9498dd72af9 (patch) | |
tree | bef1e4a0fb9565140fbf142f13d3b7e5f334031d /modules/process/manager_test.go | |
parent | 8f8c250ddbe8dfe785340cb45cbae71c4833acf3 (diff) | |
download | gitea-60c5339042a605076482320313e8f9498dd72af9.tar.gz gitea-60c5339042a605076482320313e8f9498dd72af9.zip |
Graceful: Cancel Process on monitor pages & HammerTime (#9213)
* Graceful: Create callbacks to with contexts
* Graceful: Say when Gitea is completely finished
* Graceful: Git and Process within HammerTime
Force all git commands to terminate at HammerTime
Force all process commands to terminate at HammerTime
Move almost all git processes to run as git Commands
* Graceful: Always Hammer after Shutdown
* ProcessManager: Add cancel functionality
* Fix tests
* Make sure that process.Manager.Kill() cancels
* Make threadsafe access to Processes and remove own unused Kill
* Remove cmd from the process manager as it is no longer used
* the default context is the correct context
* get rid of double till
Diffstat (limited to 'modules/process/manager_test.go')
-rw-r--r-- | modules/process/manager_test.go | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/modules/process/manager_test.go b/modules/process/manager_test.go index 9980aba921..b18f76f944 100644 --- a/modules/process/manager_test.go +++ b/modules/process/manager_test.go @@ -1,7 +1,7 @@ package process import ( - "os/exec" + "context" "testing" "time" @@ -9,27 +9,42 @@ import ( ) func TestManager_Add(t *testing.T) { - pm := Manager{Processes: make(map[int64]*Process)} + pm := Manager{processes: make(map[int64]*Process)} - pid := pm.Add("foo", exec.Command("foo")) + pid := pm.Add("foo", nil) assert.Equal(t, int64(1), pid, "expected to get pid 1 got %d", pid) - pid = pm.Add("bar", exec.Command("bar")) + pid = pm.Add("bar", nil) assert.Equal(t, int64(2), pid, "expected to get pid 2 got %d", pid) } +func TestManager_Cancel(t *testing.T) { + pm := Manager{processes: make(map[int64]*Process)} + + ctx, cancel := context.WithCancel(context.Background()) + pid := pm.Add("foo", cancel) + + pm.Cancel(pid) + + select { + case <-ctx.Done(): + default: + assert.Fail(t, "Cancel should cancel the provided context") + } +} + func TestManager_Remove(t *testing.T) { - pm := Manager{Processes: make(map[int64]*Process)} + pm := Manager{processes: make(map[int64]*Process)} - pid1 := pm.Add("foo", exec.Command("foo")) + pid1 := pm.Add("foo", nil) assert.Equal(t, int64(1), pid1, "expected to get pid 1 got %d", pid1) - pid2 := pm.Add("bar", exec.Command("bar")) + pid2 := pm.Add("bar", nil) assert.Equal(t, int64(2), pid2, "expected to get pid 2 got %d", pid2) pm.Remove(pid2) - _, exists := pm.Processes[pid2] + _, exists := pm.processes[pid2] assert.False(t, exists, "PID %d is in the list but shouldn't", pid2) } |