Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Jul 8, 2022
1 parent 766c9b7 commit afcff1a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 31 deletions.
3 changes: 2 additions & 1 deletion cluster/calcium/dissociate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func TestDissociateWorkload(t *testing.T) {
rmgr.On("SetNodeResourceUsage", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
map[string]types.NodeResourceArgs{},
map[string]types.NodeResourceArgs{},
nil)
nil,
)
store.On("RemoveWorkload", mock.Anything, mock.Anything).Return(types.ErrNoETCD).Once()
store.On("ListNodeWorkloads", mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD)
ch, err = c.DissociateWorkload(ctx, []string{"c1"})
Expand Down
2 changes: 2 additions & 0 deletions cluster/calcium/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func TestAddNode(t *testing.T) {
ctx := context.Background()
factory.InitEngineCache(ctx, c.config)
rmgr := c.rmgr.(*resourcemocks.Manager)
rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, nil, nil)
rmgr.On("ConvertNodeResourceInfoToMetrics", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*resourcetypes.Metrics{}, nil)

name := "test"
node := &types.Node{
Expand Down
4 changes: 3 additions & 1 deletion cluster/calcium/realloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
resourcetypes "github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"
Expand All @@ -20,6 +21,8 @@ func TestRealloc(t *testing.T) {
ctx := context.Background()
store := c.store.(*storemocks.Store)
rmgr := c.rmgr.(*resourcemocks.Manager)
rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, nil, nil)
rmgr.On("ConvertNodeResourceInfoToMetrics", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*resourcetypes.Metrics{}, nil)
c.config.Scheduler.ShareBase = 100

lock := &lockmocks.DistributedLock{}
Expand Down Expand Up @@ -61,7 +64,6 @@ func TestRealloc(t *testing.T) {
assert.EqualError(t, err, "ETCD must be set")
store.AssertExpectations(t)
store.On("GetNode", mock.Anything, "node1").Return(node1, nil)
rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, nil, nil)

// failed by lock
store.On("CreateLock", mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD).Once()
Expand Down
1 change: 0 additions & 1 deletion cluster/calcium/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestRemoveWorkload(t *testing.T) {
Name: "test",
},
}
// plugin.On("SetNodeResourceUsage", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil).Twice()
store.On("GetNode", mock.Anything, mock.Anything).Return(node, nil)
store.On("RemoveWorkload", mock.Anything, mock.Anything).Return(types.ErrNoETCD).Twice()
store.On("ListNodeWorkloads", mock.Anything, mock.Anything, mock.Anything).Return(nil, types.ErrNoETCD)
Expand Down
62 changes: 39 additions & 23 deletions cluster/calcium/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
enginemocks "github.com/projecteru2/core/engine/mocks"
enginetypes "github.com/projecteru2/core/engine/types"
lockmocks "github.com/projecteru2/core/lock/mocks"
"github.com/projecteru2/core/resources"
resourcetypes "github.com/projecteru2/core/resources"
resourcemocks "github.com/projecteru2/core/resources/mocks"
storemocks "github.com/projecteru2/core/store/mocks"
"github.com/projecteru2/core/types"
Expand All @@ -23,6 +23,13 @@ func TestHandleCreateWorkloadNoHandle(t *testing.T) {
wal, err := enableWAL(c.config, c, c.store)
require.NoError(t, err)
c.wal = wal
rmgr := c.rmgr.(*resourcemocks.Manager)
rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
map[string]types.NodeResourceArgs{},
map[string]types.NodeResourceArgs{},
[]string{},
nil,
)

wrkid := "workload-id"
_, err = c.wal.Log(eventWorkloadCreated, &types.Workload{ID: wrkid, Nodename: "nodename"})
Expand All @@ -48,11 +55,13 @@ func TestHandleCreateWorkloadError(t *testing.T) {
wal, err := enableWAL(c.config, c, c.store)
require.NoError(t, err)
c.wal = wal
plugin := c.rmgr.GetPlugins()[0].(*resourcemocks.Plugin)
plugin.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything).Return(&resources.GetNodeResourceInfoResponse{
ResourceInfo: &resources.NodeResourceInfo{},
Diffs: []string{"hhh"},
}, nil)
rmgr := c.rmgr.(*resourcemocks.Manager)
rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
map[string]types.NodeResourceArgs{},
map[string]types.NodeResourceArgs{},
[]string{},
nil,
)

engine := &enginemocks.API{}
node := &types.Node{
Expand Down Expand Up @@ -100,11 +109,13 @@ func TestHandleCreateWorkloadHandled(t *testing.T) {
wal, err := enableWAL(c.config, c, c.store)
require.NoError(t, err)
c.wal = wal
plugin := c.rmgr.GetPlugins()[0].(*resourcemocks.Plugin)
plugin.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything).Return(&resources.GetNodeResourceInfoResponse{
ResourceInfo: &resources.NodeResourceInfo{},
Diffs: []string{"hhh"},
}, nil)
rmgr := c.rmgr.(*resourcemocks.Manager)
rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
map[string]types.NodeResourceArgs{},
map[string]types.NodeResourceArgs{},
[]string{},
nil,
)

node := &types.Node{
NodeMeta: types.NodeMeta{Name: "nodename"},
Expand Down Expand Up @@ -145,18 +156,23 @@ func TestHandleCreateLambda(t *testing.T) {
wal, err := enableWAL(c.config, c, c.store)
require.NoError(t, err)
c.wal = wal
plugin := c.rmgr.GetPlugins()[0].(*resourcemocks.Plugin)
plugin.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything).Return(&resources.GetNodeResourceInfoResponse{
ResourceInfo: &resources.NodeResourceInfo{},
Diffs: []string{"hhh"},
}, nil)
plugin.On("SetNodeResourceUsage", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&resources.SetNodeResourceUsageResponse{
Before: types.NodeResourceArgs{},
After: types.NodeResourceArgs{},
}, nil)
plugin.On("GetRemapArgs", mock.Anything, mock.Anything, mock.Anything).Return(&resources.GetRemapArgsResponse{
EngineArgsMap: map[string]types.EngineArgs{},
}, nil)
rmgr := c.rmgr.(*resourcemocks.Manager)
rmgr.On("GetNodeResourceInfo", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
map[string]types.NodeResourceArgs{},
map[string]types.NodeResourceArgs{},
[]string{},
nil,
)
rmgr.On("SetNodeResourceUsage", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
map[string]types.NodeResourceArgs{},
map[string]types.NodeResourceArgs{},
nil,
)
rmgr.On("ConvertNodeResourceInfoToMetrics", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*resourcetypes.Metrics{}, nil)
rmgr.On("GetRemapArgs", mock.Anything, mock.Anything, mock.Anything).Return(
map[string]types.EngineArgs{},
nil,
)

_, err = c.wal.Log(eventCreateLambda, "workloadid")
require.NoError(t, err)
Expand Down
7 changes: 2 additions & 5 deletions resources/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,10 @@ func (bp *BinaryPlugin) execCommand(cmd *exec.Cmd) (output, log string, err erro
cmd.Stdout = &stdout
cmd.Stderr = &stderr

err = cmd.Run()
output = stdout.String()
log = stderr.String()
if err != nil {
if err = cmd.Run(); err != nil {
err = fmt.Errorf("err: %v, output: %v, log: %v", err, output, log)
}
return output, log, err
return stdout.String(), stderr.String(), err
}

// calls the plugin and gets json response
Expand Down

0 comments on commit afcff1a

Please sign in to comment.