-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_nonlinux_test.go
68 lines (63 loc) · 1.87 KB
/
queue_nonlinux_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//go:build !linux
package gosh_test
import (
. "github.com/meln5674/gosh/pkg/gomega"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"fmt"
"os"
"os/exec"
"github.com/meln5674/gosh"
)
var _ = Describe("Queue", func() {
When("running without a max concurrency", func() {
It("should run all processes at once", func() {
dir, err := os.MkdirTemp("", "*")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(dir)
names := []string{"a", "b", "c"}
shells := make(chan gosh.Commander)
go func() {
defer GinkgoRecover()
for _, name := range names {
shells <- gosh.Shell(allOf(
makeSentinel(dir, name),
waitForSentinels(dir, names...),
))
}
close(shells)
}()
Expect(gosh.Queue(shells).Run()).To(Succeed())
})
})
When("running with a max concurrency", func() {
It("should not run all processes at once", func() {
dir, err := os.MkdirTemp("", "*")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(dir)
names := []string{"a", "b", "c"}
shells := make(chan gosh.Commander, len(names))
cmd := gosh.Queue(shells).WithMaxConcurrency(2).WithResultBufferSize(3)
Expect(cmd.Start()).To(Succeed())
cmds := make([]*gosh.Cmd, 0, 3)
go func() {
for _, name := range names {
cmd := gosh.Shell(allOf(
makeSentinel(dir, name),
waitForSentinels(dir, names...),
))
cmds = append(cmds, cmd)
shells <- cmd
}
close(shells)
}()
Expect(gosh.Shell(waitForSentinels(dir, "a", "b")).Start()).To(Succeed())
Expect(cmd.Kill()).To(Succeed())
Expect(fmt.Sprintf("%s/%s", dir, "c")).ToNot(BeARegularFile())
Expect(cmd.Wait()).To(Or(MatchMultiProcessError(gosh.ErrKilled), MatchMultiProcessErrorType(&exec.ExitError{})))
Expect(cmds[0].ProcessState).ToNot(BeNil())
Expect(cmds[1].ProcessState).ToNot(BeNil())
Expect(cmds[2].ProcessState).To(BeNil())
})
})
})