forked from cloudfoundry/cf-acceptance-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
49 lines (40 loc) · 1.15 KB
/
log.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
package log
import (
"fmt"
"io"
"net/http"
"strconv"
"time"
"code.cloudfoundry.org/clock"
"github.com/gorilla/mux"
)
func MakeSpewHandler(w io.Writer) func(http.ResponseWriter, *http.Request) {
return func(res http.ResponseWriter, req *http.Request) {
kbytes, _ := strconv.Atoi(mux.Vars(req)["kbytes"])
k := make([]byte, 1024)
for i := range k {
k[i] = '1'
}
for i := 0; i < kbytes; i++ {
fmt.Fprintf(w, "%s\n", k)
}
io.WriteString(res, fmt.Sprintf("Just wrote %d kbytes to the log", kbytes))
}
}
func MakeSleepHandler(w io.Writer, clock clock.Clock) func(http.ResponseWriter, *http.Request) {
return func(res http.ResponseWriter, req *http.Request) {
logSpeed, _ := strconv.Atoi(mux.Vars(req)["logspeed"])
fmt.Fprintf(w, "Muahaha... let's go. Waiting %f seconds between loglines. Logging 'Muahaha...' every time.\n", float64(logSpeed)/1000000.0)
sequence := 1
ticker := clock.NewTicker(time.Duration(logSpeed) * time.Microsecond)
go func() {
for {
select {
case t := <-ticker.C():
fmt.Fprintf(w, "Log: %s Muahaha...%d...%s\n", req.Host, sequence, t.Format(time.RFC3339))
sequence++
}
}
}()
}
}