Skip to content

Commit

Permalink
Fix RPCGateway tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Oct 27, 2019
1 parent 2690d45 commit 2a373d3
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 127 deletions.
38 changes: 38 additions & 0 deletions pkg/app2/appcommon/mock_addr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/app2/mock_conn.go → pkg/app2/appcommon/mock_conn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions pkg/app2/appcommon/proc.go → pkg/app2/appserver/proc.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package appcommon
package appserver

import (
"fmt"
"github.com/skycoin/skywire/pkg/app2/appserver"
"io"
"os/exec"
"path/filepath"

"github.com/skycoin/skywire/pkg/app2/appcommon"

"github.com/skycoin/skycoin/src/util/logging"
)

// Proc is a wrapper for a skywire app. Encapsulates
// the running proccess itself and the RPC server for
// app/visor communication.
type Proc struct {
key Key
config Config
key appcommon.Key
config appcommon.Config
log *logging.Logger
rpcS *appserver.Server
rpcS *Server
cmd *exec.Cmd
}

// NewProc constructs `Proc`.
func NewProc(log *logging.Logger, c Config, args []string, stdout, stderr io.Writer) (*Proc, error) {
key := GenerateAppKey()
func NewProc(log *logging.Logger, c appcommon.Config, args []string, stdout, stderr io.Writer) (*Proc, error) {
key := appcommon.GenerateAppKey()

binaryPath := getBinaryPath(c.BinaryDir, c.Name, c.Version)

Expand All @@ -44,7 +45,7 @@ func NewProc(log *logging.Logger, c Config, args []string, stdout, stderr io.Wri
cmd.Stdout = stdout
cmd.Stderr = stderr

rpcS, err := appserver.New(logging.MustGetLogger(fmt.Sprintf("app_rpc_server_%s", key)),
rpcS, err := New(logging.MustGetLogger(fmt.Sprintf("app_rpc_server_%s", key)),
c.SockFile, key)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package appcommon
package appserver

import (
"fmt"
"io"
"os/exec"
"sync"

"github.com/skycoin/skywire/pkg/app2/apputil"
"github.com/skycoin/skywire/pkg/app2/appcommon"

"github.com/pkg/errors"

Expand Down Expand Up @@ -34,8 +34,8 @@ func NewProcManager(log *logging.Logger) *ProcManager {
}

// Run runs the application according to its config and additional args.
func (m *ProcManager) Run(log *logging.Logger, c Config, args []string,
stdout, stderr io.Writer) (ProcID, error) {
func (m *ProcManager) Run(log *logging.Logger, c appcommon.Config, args []string,
stdout, stderr io.Writer) (appcommon.ProcID, error) {
if m.Exists(c.Name) {
return 0, errAppAlreadyExists
}
Expand All @@ -60,12 +60,12 @@ func (m *ProcManager) Run(log *logging.Logger, c Config, args []string,
m.procs[c.Name] = p
m.mx.Unlock()

return apputil.ProcID(p.cmd.Process.Pid), nil
return appcommon.ProcID(p.cmd.Process.Pid), nil
}

// Exists check whether app exists in the manager instance.
func (m *ProcManager) Exists(name string) bool {
m.mx.RUnlock()
m.mx.RLock()
defer m.mx.RUnlock()

_, ok := m.procs[name]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package appcommon
package appserver

import (
"sort"
"testing"

"github.com/stretchr/testify/require"

"github.com/skycoin/skycoin/src/util/logging"
"github.com/stretchr/testify/require"
)

func TestProcManager_Exists(t *testing.T) {
Expand Down
Loading

0 comments on commit 2a373d3

Please sign in to comment.