From c7c1e72eaf3dc4133da1a2487553354ec7b98fde Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 1 Feb 2016 16:35:22 -0800 Subject: [PATCH] add sharness test License: MIT Signed-off-by: Jeromy --- commands/reqlog.go | 3 -- core/commands/active.go | 4 +- test/sharness/t0065-active-requests.sh | 52 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) create mode 100755 test/sharness/t0065-active-requests.sh diff --git a/commands/reqlog.go b/commands/reqlog.go index acc7ddcfb7b..581f4cedc69 100644 --- a/commands/reqlog.go +++ b/commands/reqlog.go @@ -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, @@ -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() } diff --git a/core/commands/active.go b/core/commands/active.go index f91d8006499..3a3249bca13 100644 --- a/core/commands/active.go +++ b/core/commands/active.go @@ -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() diff --git a/test/sharness/t0065-active-requests.sh b/test/sharness/t0065-active-requests.sh new file mode 100755 index 00000000000..36dfb517230 --- /dev/null +++ b/test/sharness/t0065-active-requests.sh @@ -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