Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions _examples/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ verbose: %t`, method, url, timeout, postFile, contentType, disableCompression, d
Timeout: time.Duration(timeout) * time.Second,
}

// Update the host URL passed from UI
boomer.Events.Subscribe(boomer.EVENT_SPAWN3, func(workers int, spawnRate float64, host string) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about a more understandable name like boomer.EVENT_CONFIG?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense! I applied that f090ff9

url = host
})

task := &boomer.Task{
Name: "worker",
Weight: 10,
Expand Down
1 change: 1 addition & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "github.com/asaskevich/EventBus"
const (
EVENT_CONNECTED = "boomer:connected"
EVENT_SPAWN = "boomer:spawn"
EVENT_SPAWN3 = "boomer:spawn3"
EVENT_STOP = "boomer:stop"
EVENT_QUIT = "boomer:quit"
)
Expand Down
14 changes: 11 additions & 3 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type runner struct {

numClients int32
spawnRate float64
targetHost string
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to keep this field. Publishing an event is enough.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the field in a553bd9 .


// Cancellation method for all running workers(goroutines)
cancelFuncs []context.CancelFunc
Expand Down Expand Up @@ -246,8 +247,9 @@ func (r *runner) getTask(index int) *Task {
return r.runTask[index]
}

func (r *runner) startSpawning(spawnCount int, spawnRate float64, spawnCompleteFunc func()) {
func (r *runner) startSpawning(spawnCount int, spawnRate float64, host string, spawnCompleteFunc func()) {
Events.Publish(EVENT_SPAWN, spawnCount, spawnRate)
Events.Publish(EVENT_SPAWN3, spawnCount, spawnRate, host)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about Events.Publish(EVENT_CONFIG, "host", host)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified the code to publish the boomer:config event along with a map f090ff9 .
Is this what you meant?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thanks


r.spawnWorkers(spawnCount, spawnCompleteFunc)
}
Expand Down Expand Up @@ -310,7 +312,7 @@ func (r *localRunner) run() {
if r.rateLimitEnabled {
r.rateLimiter.Start()
}
r.startSpawning(r.spawnCount, r.spawnRate, nil)
r.startSpawning(r.spawnCount, r.spawnRate, r.targetHost, nil)

wg.Wait()
}
Expand Down Expand Up @@ -429,9 +431,15 @@ func (r *slaveRunner) onSpawnMessage(msg *genericMessage) {
}
}

if host, ok := msg.Data["host"]; ok {
if host, ok := host.([]byte); ok {
r.targetHost = string(host)
}
}

r.client.sendChannel() <- newGenericMessage("spawning", nil, r.nodeID)
workers := r.sumUsersAmount(msg)
r.startSpawning(workers, float64(workers), r.spawnComplete)
r.startSpawning(workers, float64(workers), r.targetHost, r.spawnComplete)
}

// TODO: consider to add register_message instead of publishing any unknown type as custom_message.
Expand Down
37 changes: 36 additions & 1 deletion runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ var _ = Describe("Test runner", func() {
runner.client = newClient("localhost", 5557, runner.nodeID)
defer runner.shutdown()

runner.startSpawning(10, float64(10), runner.spawnComplete)
runner.startSpawning(10, float64(10), "http://localhost:8080", runner.spawnComplete)
// wait for spawning goroutines
time.Sleep(2 * time.Second)
Expect(runner.numClients).To(BeEquivalentTo(10))
Expand Down Expand Up @@ -327,6 +327,41 @@ var _ = Describe("Test runner", func() {
runner.onMessage(newGenericMessage("stop", nil, runner.nodeID))
})

It("test on spawn message with three arguments", func() {
taskA := &Task{
Fn: func() {
time.Sleep(time.Second)
},
}
runner := newSlaveRunner("localhost", 5557, []*Task{taskA}, nil)
runner.client = newClient("localhost", 5557, runner.nodeID)
runner.state = stateInit
defer runner.shutdown()

workers, spawnRate, host := 0, float64(0), ""
callback := func(param1 int, param2 float64, param3 string) {
workers = param1
spawnRate = param2
host = param3
}
Events.Subscribe(EVENT_SPAWN3, callback)
defer Events.Unsubscribe(EVENT_SPAWN3, callback)

runner.onSpawnMessage(newGenericMessage("spawn", map[string]interface{}{
"user_classes_count": map[interface{}]interface{}{
"Dummy": int64(10),
"Dummy2": int64(10),
},
"timestamp": 1,
"host": []byte("http://localhost:3000"),
}, runner.nodeID))

Expect(workers).To(BeEquivalentTo(20))
Expect(spawnRate).To(BeEquivalentTo(20))
Expect(host).To(BeEquivalentTo("http://localhost:3000"))
runner.onMessage(newGenericMessage("stop", nil, runner.nodeID))
})

It("test onQuitMessage", func() {
runner := newSlaveRunner("localhost", 5557, nil, nil)
runner.client = newClient("localhost", 5557, "test")
Expand Down