Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make host url configurable from UI #205

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions _examples/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ 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_CONFIG, func(params map[string]interface{}) {
if v, ok := params["host"]; ok {
url = v.(string)
}
})

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_CONFIG = "boomer:config"
EVENT_STOP = "boomer:stop"
EVENT_QUIT = "boomer:quit"
)
Expand Down
16 changes: 13 additions & 3 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,11 @@ 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_CONFIG, map[string]interface{}{
"host": host,
})

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

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

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

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

// TODO: consider to add register_message instead of publishing any unknown type as custom_message.
Expand Down
13 changes: 12 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 @@ -314,16 +314,27 @@ var _ = Describe("Test runner", func() {
Events.Subscribe(EVENT_SPAWN, callback)
defer Events.Unsubscribe(EVENT_SPAWN, callback)

host := ""
configCallback := func(params map[string]interface{}) {
if v, ok := params["host"]; ok {
host = v.(string)
}
}
Events.Subscribe(EVENT_CONFIG, configCallback)
defer Events.Unsubscribe(EVENT_CONFIG, configCallback)

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))
})

Expand Down