add sharness test
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Feb 1, 2016 at 16:35 UTC
c7c1e72eaf3dc4133da1a2487553354ec7b98fde
3 files changed
+54
-5
commands/reqlog.go
-3
@@ -45,7 +45,6 @@ func (rl *ReqLog) Add(req Request) *ReqLogEntry {
45
rl.lock.Lock()
46
defer rl.lock.Unlock()
47
48
- log.Error("ADD: ", req)
48
rle := &ReqLogEntry{
49
StartTime: time.Now(),
50
Active: true,
@@ -95,8 +94,6 @@ func (rl *ReqLog) Report() []*ReqLogEntry {
94
defer rl.lock.Unlock()
95
out := make([]*ReqLogEntry, len(rl.Requests))
96
98
- log.Error("REPORT: ", rl.Requests)
99
-
97
for i, e := range rl.Requests {
98
out[i] = e.Copy()
99
}
core/commands/active.go
+2
-2
@@ -33,9 +33,9 @@ Lists running and recently run commands.
33
fmt.Fprintln(w, "Command\tActive\tStartTime\tRunTime")
34
for _, req := range *out {
35
if req.Active {
36
- fmt.Fprintf(w, "%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
36
+ fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
37
} else {
38
- fmt.Fprintf(w, "%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
38
+ fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
39
}
40
}
41
w.Flush()
test/sharness/t0065-active-requests.sh
new
+52
@@ -0,0 +1,52 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2016 Jeromy Johnson
4
+# MIT Licensed; see the LICENSE file in this repository.
5
+#
6
+
7
+test_description="Test active request commands"
8
+
9
+. lib/test-lib.sh
10
+
11
+test_init_ipfs
12
+test_launch_ipfs_daemon
13
+
14
+test_expect_success "command works" '
15
+ ipfs diag cmds > cmd_out
16
+'
17
+
18
+test_expect_success "invoc shows up in output" '
19
+ grep "diag/cmds" cmd_out > /dev/null
20
+'
21
+
22
+test_expect_success "start longer running command" '
23
+ ipfs log tail &
24
+ LOGPID=$!
25
+'
26
+
27
+test_expect_success "long running command shows up" '
28
+ ipfs diag cmds > cmd_out2
29
+'
30
+
31
+test_expect_success "output looks good" '
32
+ grep "log/tail" cmd_out2 | grep "true" > /dev/null
33
+'
34
+
35
+test_expect_success "kill log cmd" '
36
+ kill $LOGPID
37
+ go-sleep 0.5s
38
+ kill $LOGPID
39
+
40
+ wait $LOGPID || true
41
+'
42
+
43
+test_expect_success "long running command inactive" '
44
+ ipfs diag cmds > cmd_out3
45
+'
46
+
47
+test_expect_success "command shows up as inactive" '
48
+ grep "log/tail" cmd_out3 | grep "false"
49
+'
50
+
51
+test_kill_ipfs_daemon
52
+test_done