github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/shell/subtree_windows_test.go (about) 1 // +build windows 2 3 package shell 4 5 import ( 6 "fmt" 7 "sync" 8 "testing" 9 10 "github.com/mongodb/grip" 11 "github.com/mongodb/grip/send" 12 . "github.com/smartystreets/goconvey/convey" 13 ) 14 15 func init() { 16 err := grip.SetSender(send.MakeNative()) 17 grip.CatchError(err) 18 } 19 20 func TestWindowsProcessRegistry(t *testing.T) { 21 reg := newProcessRegistry() 22 Convey("the process registry", t, func() { 23 So(len(reg.jobs), ShouldEqual, 0) 24 25 Reset(func() { 26 reg = newProcessRegistry() 27 So(len(reg.jobs), ShouldEqual, 0) 28 }) 29 30 Convey("should store new jobs", func() { 31 for i := 0; i < 10; i++ { 32 id := fmt.Sprintf("job-%d", i) 33 j, err := reg.getJob(id) 34 So(j, ShouldNotBeNil) 35 So(err, ShouldBeNil) 36 } 37 So(len(reg.jobs), ShouldEqual, 10) 38 }) 39 40 Convey("should support concurrent operations", func(c C) { 41 const ( 42 numWorkers = 10 43 numJobs = 40 44 ) 45 46 wg := &sync.WaitGroup{} 47 48 for w := 0; w < numWorkers; w++ { 49 wg.Add(1) 50 go func(num int, c C) { 51 defer wg.Done() 52 for i := 0; i < numJobs; i++ { 53 id := fmt.Sprintf("job-%d.%d", num, i) 54 j, err := reg.getJob(id) 55 c.So(j, ShouldNotBeNil) 56 c.So(err, ShouldBeNil) 57 } 58 }(w, c) 59 } 60 61 wg.Wait() 62 So(len(reg.jobs), ShouldEqual, numJobs*numWorkers) 63 }) 64 65 Convey("should de-duplicate jobs by given id", func() { 66 ids := []string{"one", "two", "three"} 67 for i := 0; i < 10; i++ { 68 for _, id := range ids { 69 j, err := reg.getJob(id) 70 So(j, ShouldNotBeNil) 71 So(err, ShouldBeNil) 72 } 73 } 74 75 So(len(reg.jobs), ShouldEqual, len(ids)) 76 }) 77 78 Convey("remove should try to remove tracked jobs", func() { 79 const id = "jobName" 80 j, err := reg.getJob(id) 81 So(j, ShouldNotBeNil) 82 So(err, ShouldBeNil) 83 So(len(reg.jobs), ShouldEqual, 1) 84 85 grip.CatchError(reg.removeJob(id)) 86 So(len(reg.jobs), ShouldEqual, 0) 87 }) 88 }) 89 }