-
Notifications
You must be signed in to change notification settings - Fork 0
/
fanout_nonlinux_test.go
55 lines (50 loc) · 1.56 KB
/
fanout_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
//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("FanOut", 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([]gosh.Commander, 0, len(names))
for _, name := range names {
shells = append(shells, gosh.Shell(allOf(
makeSentinel(dir, name),
waitForSentinels(dir, names...),
)))
}
Expect(gosh.FanOut(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([]gosh.Commander, 0, len(names))
for _, name := range names {
shells = append(shells, gosh.Shell(allOf(
makeSentinel(dir, name),
waitForSentinels(dir, names...),
)))
}
cmd := gosh.FanOut(shells...).WithMaxConcurrency(2)
Expect(cmd.Start()).To(Succeed())
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{})))
})
})
})