Skip to content

Commit

Permalink
add sharness test
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Feb 2, 2016
1 parent 366d7db commit c7c1e72
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
3 changes: 0 additions & 3 deletions commands/reqlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (rl *ReqLog) Add(req Request) *ReqLogEntry {
rl.lock.Lock()
defer rl.lock.Unlock()

log.Error("ADD: ", req)
rle := &ReqLogEntry{
StartTime: time.Now(),
Active: true,
Expand Down Expand Up @@ -95,8 +94,6 @@ func (rl *ReqLog) Report() []*ReqLogEntry {
defer rl.lock.Unlock()
out := make([]*ReqLogEntry, len(rl.Requests))

log.Error("REPORT: ", rl.Requests)

for i, e := range rl.Requests {
out[i] = e.Copy()
}
Expand Down
4 changes: 2 additions & 2 deletions core/commands/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Lists running and recently run commands.
fmt.Fprintln(w, "Command\tActive\tStartTime\tRunTime")
for _, req := range *out {
if req.Active {
fmt.Fprintf(w, "%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
} else {
fmt.Fprintf(w, "%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
}
}
w.Flush()
Expand Down
52 changes: 52 additions & 0 deletions test/sharness/t0065-active-requests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
#
# Copyright (c) 2016 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test active request commands"

. lib/test-lib.sh

test_init_ipfs
test_launch_ipfs_daemon

test_expect_success "command works" '
ipfs diag cmds > cmd_out
'

test_expect_success "invoc shows up in output" '
grep "diag/cmds" cmd_out > /dev/null
'

test_expect_success "start longer running command" '
ipfs log tail &
LOGPID=$!
'

test_expect_success "long running command shows up" '
ipfs diag cmds > cmd_out2
'

test_expect_success "output looks good" '
grep "log/tail" cmd_out2 | grep "true" > /dev/null
'

test_expect_success "kill log cmd" '
kill $LOGPID
go-sleep 0.5s
kill $LOGPID
wait $LOGPID || true
'

test_expect_success "long running command inactive" '
ipfs diag cmds > cmd_out3
'

test_expect_success "command shows up as inactive" '
grep "log/tail" cmd_out3 | grep "false"
'

test_kill_ipfs_daemon
test_done

1 comment on commit c7c1e72

@chriscool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sharness tests LGTM!

Please sign in to comment.