-
Notifications
You must be signed in to change notification settings - Fork 42
/
status.go
78 lines (67 loc) · 1.89 KB
/
status.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package loadtest
import (
"encoding/json"
"errors"
"strings"
"time"
)
// State determines which state a loadtester is in.
type State int
// Different possible states of a loadtester.
const (
Stopped State = iota
Starting
Running
Stopping
)
// ErrInvalidState is returned when an unknown state variable is encoded/decoded.
var ErrInvalidState = errors.New("unknown state")
// UnmarshalJSON constructs the state from a JSON string.
func (s *State) UnmarshalJSON(b []byte) error {
var res string
if err := json.Unmarshal(b, &res); err != nil {
return err
}
switch strings.ToLower(res) {
default:
return ErrInvalidState
case "stopped":
*s = Stopped
case "starting":
*s = Starting
case "running":
*s = Running
case "stopping":
*s = Stopping
}
return nil
}
// MarshalJSON returns a JSON representation from a State variable.
func (s State) MarshalJSON() ([]byte, error) {
var res string
switch s {
default:
return nil, ErrInvalidState
case Stopped:
res = "stopped"
case Starting:
res = "starting"
case Running:
res = "running"
case Stopping:
res = "stopping"
}
return json.Marshal(res)
}
// Status contains various information about the load test.
type Status struct {
State State // State of the load test.
NumUsers int64 // Number of active users.
NumUsersAdded int64 // Number of users added since the start of the test.
NumUsersRemoved int64 // Number of users removed since the start of the test.
NumUsersStopped int64 // Number of users that stopped running.
NumErrors int64 // Number of errors that have occurred.
StartTime time.Time // Time when the load test was started. This only logs the time when the load test was first started, and does not get reset if it was subsequently restarted.
}