Skip to content

Commit

Permalink
fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
egonelbre committed Sep 11, 2018
1 parent c8d2420 commit 90e0964
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
6 changes: 4 additions & 2 deletions internal/processgroup/kill_fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
"os/exec"
)

// Setup sets up exec.Cmd such that it can be properly terminated
func Setup(c *exec.Cmd) {}

// Kill tries to forcefully kill the process
func Kill(cmd *exec.Cmd) {
proc := cmd.Process
if proc == nil {
return
}
proc.Signal(os.Interrupt)
proc.Signal(os.Kill)
_ = proc.Signal(os.Interrupt)
_ = proc.Signal(os.Kill)
}
8 changes: 5 additions & 3 deletions internal/processgroup/kill_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"syscall"
)

// Setup sets up exec.Cmd such that it can be properly terminated
func Setup(c *exec.Cmd) {
c.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
}

// Kill tries to forcefully kill the process
func Kill(cmd *exec.Cmd) {
proc := cmd.Process
if proc == nil {
Expand All @@ -25,10 +27,10 @@ func Kill(cmd *exec.Cmd) {

pgid, err := syscall.Getpgid(proc.Pid)
if err != nil {
syscall.Kill(-pgid, 15)
_ = syscall.Kill(-pgid, 15)
}

// just in case
proc.Signal(os.Interrupt)
proc.Signal(os.Kill)
_ = proc.Signal(os.Interrupt)
_ = proc.Signal(os.Kill)
}
8 changes: 5 additions & 3 deletions internal/processgroup/kill_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ import (
"syscall"
)

// Setup sets up exec.Cmd such that it can be properly terminated
func Setup(c *exec.Cmd) {
c.SysProcAttr = &syscall.SysProcAttr{
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
}
}

// Kill tries to forcefully kill the process
func Kill(cmd *exec.Cmd) {
proc := cmd.Process
if proc == nil {
return
}

exec.Command("taskkill", "/f", "/pid", strconv.Itoa(proc.Pid)).Run()
_ = exec.Command("taskkill", "/f", "/pid", strconv.Itoa(proc.Pid)).Run()

// just in case
forcekill(proc.Pid)
proc.Signal(os.Interrupt)
proc.Signal(os.Kill)
_ = proc.Signal(os.Interrupt)
_ = proc.Signal(os.Kill)
}

func forcekill(pid int) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kademlia/routing_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func tempdir(t testing.TB) (dir string, cleanup func()) {
dir, err := ioutil.TempDir("", "kademlia")
dir, err := ioutil.TempDir("", "storj-kademlia")
if err != nil {
t.Fatal(err)
}
Expand Down
38 changes: 24 additions & 14 deletions pkg/piecestore/rpc/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"runtime"
"strings"
"testing"
"time"

"github.com/gogo/protobuf/proto"
"github.com/gtank/cryptopasta"
Expand Down Expand Up @@ -462,21 +461,31 @@ func TestDelete(t *testing.T) {
}
}

func newTestServerStruct() *Server {
tmp, err := ioutil.TempDir("", "example")
func newTestServerStruct(t *testing.T) (*Server, func()) {
tmp, err := ioutil.TempDir("", "storj-piecestore")
if err != nil {
log.Fatalf("failed temp-dir: %v", err)
}

tempDBPath := filepath.Join(tmp, fmt.Sprintf("%s-test.db", time.Now().Format("2006-01-02T15-04-05.999999999Z07-00")))
tempDBPath := filepath.Join(tmp, "test.db")
tempDir := filepath.Join(tmp, "test-data", "3000")

psDB, err := psdb.Open(ctx, tempDir, tempDBPath)
if err != nil {
log.Fatalf("failed open psdb: %v", err)
t.Fatalf("failed open psdb: %v", err)
}

return &Server{DataDir: tempDir, DB: psDB}
server := &Server{DataDir: tempDir, DB: psDB}
return server, func() {
if serr := server.Stop(ctx); serr != nil {
t.Fatal(serr)
}
// TODO:fix this error check
_ = os.RemoveAll(tmp)
// if err := os.RemoveAll(tmp); err != nil {
// t.Fatal(err)
// }
}
}

func connect(addr string, o ...grpc.DialOption) (pb.PieceStoreRoutesClient, *grpc.ClientConn) {
Expand All @@ -491,11 +500,12 @@ func connect(addr string, o ...grpc.DialOption) (pb.PieceStoreRoutesClient, *grp
}

type TestServer struct {
s *Server
grpcs *grpc.Server
conn *grpc.ClientConn
c pb.PieceStoreRoutesClient
k crypto.PrivateKey
s *Server
scleanup func()
grpcs *grpc.Server
conn *grpc.ClientConn
c pb.PieceStoreRoutesClient
k crypto.PrivateKey
}

func NewTestServer(t *testing.T) *TestServer {
Expand All @@ -519,12 +529,12 @@ func NewTestServer(t *testing.T) *TestServer {
co, err := fiC.DialOption()
check(err)

s := newTestServerStruct()
s, cleanup := newTestServerStruct(t)
grpcs := grpc.NewServer(so)

k, ok := fiC.Key.(*ecdsa.PrivateKey)
assert.True(t, ok)
ts := &TestServer{s: s, grpcs: grpcs, k: k}
ts := &TestServer{s: s, scleanup: cleanup, grpcs: grpcs, k: k}
addr := ts.start()
ts.c, ts.conn = connect(addr, co)

Expand All @@ -549,7 +559,7 @@ func (TS *TestServer) start() (addr string) {
func (TS *TestServer) Stop() {
TS.conn.Close()
TS.grpcs.Stop()
os.RemoveAll(TS.s.DataDir)
TS.scleanup()
}

func serializeData(ba *pb.RenterBandwidthAllocation_Data) []byte {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestIdentityConfig_SaveIdentity(t *testing.T) {
}

func tempIdentityConfig() (*IdentityConfig, func(), error) {
tmpDir, err := ioutil.TempDir("", "tempIdentity")
tmpDir, err := ioutil.TempDir("", "storj-identity")
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions storage/boltdb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func TestSuite(t *testing.T) {
tempdir, err := ioutil.TempDir("", "bolt")
tempdir, err := ioutil.TempDir("", "storj-bolt")
if err != nil {
t.Fatal(err)
}
Expand All @@ -34,7 +34,7 @@ func TestSuite(t *testing.T) {
}

func BenchmarkSuite(b *testing.B) {
tempdir, err := ioutil.TempDir("", "bolt")
tempdir, err := ioutil.TempDir("", "storj-bolt")
if err != nil {
b.Fatal(err)
}
Expand Down

0 comments on commit 90e0964

Please sign in to comment.