/
main.go
58 lines (49 loc) · 1.55 KB
/
main.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
56
57
58
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// The following enables go generate to generate the doc.go file.
//go:generate go run v.io/x/lib/cmdline/gendoc . -help
package main
import (
"time"
v23 "v.io/v23"
"v.io/v23/context"
"v.io/v23/security"
"v.io/x/lib/cmdline"
"v.io/x/ref/lib/signals"
"v.io/x/ref/lib/v23cmd"
_ "v.io/x/ref/runtime/factories/roaming"
"v.io/x/ref/runtime/internal/rpc/stress/internal"
)
var duration time.Duration
var name string
func main() {
cmdRoot.Flags.DurationVar(&duration, "duration", 0, "Duration of the stress test to run; if zero, there is no limit.")
cmdRoot.Flags.StringVar(&name, "name", "", "Name to mount the server under. If empty, don't mount.")
cmdline.HideGlobalFlagsExcept()
cmdline.Main(cmdRoot)
}
var cmdRoot = &cmdline.Command{
Runner: v23cmd.RunnerFunc(runStressD),
Name: "stressd",
Short: "Run the stress-test server",
Long: "Command stressd runs the stress-test server.",
}
func runStressD(ctx *context.T, env *cmdline.Env, args []string) error {
service, stop := internal.NewService()
ctx, server, err := v23.WithNewServer(ctx, name, service, security.AllowEveryone())
if err != nil {
ctx.Fatalf("NewServer failed: %v", err)
}
ctx.Infof("listening on %s", server.Status().Endpoints[0].Name())
var timeout <-chan time.Time
if duration > 0 {
timeout = time.After(duration)
}
select {
case <-timeout:
case <-stop:
case <-signals.ShutdownOnSignals(ctx):
}
return nil
}