Skip to content

Commit

Permalink
add test func
Browse files Browse the repository at this point in the history
  • Loading branch information
MyNextWeekend committed Sep 23, 2023
1 parent 4e3c0f9 commit 1fcecb1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ func (r *slaveRunner) shutdown() {
if r.rateLimitEnabled {
r.rateLimiter.Stop()
}
r.cancelFuncs = nil
r.numClients = 0
close(r.shutdownChan)
}

Expand Down
47 changes: 42 additions & 5 deletions runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,46 @@ var _ = Describe("Test runner", func() {
Expect(hitOutput2.onStop).To(BeTrue())
})

It("test add workers", func() {
taskA := &Task{
Weight: 10,
Fn: func() {
time.Sleep(time.Second)
},
Name: "TaskA",
}

runner := newSlaveRunner("localhost", 5557, []*Task{taskA}, nil)
runner.client = newClient("localhost", 5557, runner.nodeID)
defer runner.shutdown()

runner.addWorkers(10)

currentClients := len(runner.cancelFuncs)
Expect(currentClients).To(BeEquivalentTo(10))
})

It("test reduce workers", func() {
taskA := &Task{
Weight: 10,
Fn: func() {
time.Sleep(time.Second)
},
Name: "TaskA",
}

runner := newSlaveRunner("localhost", 5557, []*Task{taskA}, nil)
runner.client = newClient("localhost", 5557, runner.nodeID)
defer runner.shutdown()

runner.addWorkers(10)
runner.reduceWorkers(5)
runner.reduceWorkers(2)

currentClients := len(runner.cancelFuncs)
Expect(currentClients).To(BeEquivalentTo(3))
})

It("test localrunner", func() {
taskA := &Task{
Weight: 10,
Expand Down Expand Up @@ -120,8 +160,7 @@ var _ = Describe("Test runner", func() {
runner.client = newClient("localhost", 5557, runner.nodeID)
defer runner.shutdown()

go runner.spawnWorkers(10, runner.stopChan, runner.spawnComplete)
time.Sleep(10 * time.Millisecond)
runner.spawnWorkers(10, runner.spawnComplete)

currentClients := atomic.LoadInt32(&runner.numClients)
Expect(currentClients).To(BeEquivalentTo(10))
Expand Down Expand Up @@ -162,7 +201,7 @@ var _ = Describe("Test runner", func() {

const numToSpawn int = 30

runner.spawnWorkers(numToSpawn, runner.stopChan, runner.spawnComplete)
runner.spawnWorkers(numToSpawn, runner.spawnComplete)
time.Sleep(3 * time.Second)

currentClients := atomic.LoadInt32(&runner.numClients)
Expand Down Expand Up @@ -238,7 +277,6 @@ var _ = Describe("Test runner", func() {
}

runner := newSlaveRunner("localhost", 5557, []*Task{taskA}, nil)
runner.stopChan = make(chan bool)

stopped := false
handler := func() {
Expand Down Expand Up @@ -301,7 +339,6 @@ var _ = Describe("Test runner", func() {
Eventually(quitMessages).Should(Receive())

runner.state = stateRunning
runner.stopChan = make(chan bool)
runner.onMessage(newGenericMessage("quit", nil, runner.nodeID))
Eventually(quitMessages).Should(Receive())
Expect(runner.state).Should(BeIdenticalTo(stateInit))
Expand Down

0 comments on commit 1fcecb1

Please sign in to comment.