Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: change time-out script to one from coreutils #3152

Merged
merged 3 commits into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

BINS = bin/random bin/multihash bin/ipfs bin/pollEndpoint bin/iptb bin/go-sleep
BINS += bin/go-timeout
IPFS_ROOT = ../
IPFS_CMD = ../cmd/ipfs
RANDOM_SRC = ../Godeps/_workspace/src/github.com/jbenet/go-random
RANDOM_FILES_SRC = ../Godeps/_workspace/src/github.com/jbenet/go-random-files
POLLENDPOINT_SRC= ../thirdparty/pollEndpoint
GOSLEEP_SRC = ./dependencies/go-sleep
GOTIMEOUT_SRC = ./dependencies/go-timeout

export PATH := ../bin:${PATH}

Expand Down Expand Up @@ -48,6 +50,10 @@ bin/go-sleep: $(call find_go_files, $(GOSLEEP_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/go-sleep $(GOSLEEP_SRC)

bin/go-timeout: $(call find_go_files, $(GOTIMEOUT_SRC)) IPFS-BUILD-OPTIONS
@echo "*** installing $@ ***"
go build $(GOFLAGS) -o bin/go-timeout $(GOTIMEOUT_SRC)

# gx dependencies

multihash_src:
Expand Down
1 change: 0 additions & 1 deletion test/bin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
!checkflags
!continueyn
!verify-go-fmt.sh
!time-out
83 changes: 0 additions & 83 deletions test/bin/time-out

This file was deleted.

1 change: 1 addition & 0 deletions test/dependencies/go-timeout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go-timeout
22 changes: 22 additions & 0 deletions test/dependencies/go-timeout/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2016 Jakub "Kubuxu" Sztandera <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

55 changes: 55 additions & 0 deletions test/dependencies/go-timeout/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"context"
"fmt"
"os"
"os/exec"
"strconv"
"syscall"
"time"
)

func main() {
if len(os.Args) < 3 {
fmt.Fprintf(os.Stderr,
"Usage: %s <timeout-in-sec> <command ...>\n", os.Args[0])
os.Exit(1)
}
timeout, err := strconv.ParseUint(os.Args[1], 10, 32)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
ctx, _ := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)

cmd := exec.CommandContext(ctx, os.Args[2], os.Args[3:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Start()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
err = cmd.Wait()

if err != nil {
if ctx.Err() != nil {
os.Exit(124)
} else {
exitErr, ok := err.(*exec.ExitError)
if !ok {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(255)
}
waits, ok := exitErr.Sys().(syscall.WaitStatus)
if !ok {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(255)
}
os.Exit(waits.ExitStatus())
}
} else {
os.Exit(0)
}
}
2 changes: 1 addition & 1 deletion test/sharness/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
BINS = bin/random bin/multihash bin/ipfs bin/pollEndpoint \
bin/iptb bin/go-sleep bin/random-files
bin/iptb bin/go-sleep bin/random-files bin/go-timeout
SHARNESS = lib/sharness/sharness.sh
IPFS_ROOT = ../..

Expand Down
10 changes: 5 additions & 5 deletions test/sharness/t0500-issues-and-regressions-offline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ test_description="Tests for various fixed issues and regressions."

test_expect_success "ipfs init with occupied input works - #2748" '
export IPFS_PATH="ipfs_path"
echo "" | time-out ipfs init &&
echo "" | go-timeout 10 ipfs init &&
rm -rf ipfs_path
'
test_init_ipfs

test_expect_success "ipfs cat --help succeeds with no input" '
time-out ipfs cat --help
test_expect_success "ipfs cat --help succeeds when input remains open" '
yes | go-timeout 1 ipfs cat --help
'

test_expect_success "ipfs pin ls --help succeeds with no input" '
time-out ipfs pin ls --help
test_expect_success "ipfs pin ls --help succeeds when input remains open" '
yes | go-timeout 1 ipfs pin ls --help
'

test_expect_success "ipfs add on 1MB from stdin woks" '
Expand Down