Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zygimantass committed Jan 15, 2025
1 parent 3f1f100 commit 007ace9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 31 deletions.
8 changes: 2 additions & 6 deletions core/provider/docker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ func (p *Provider) ensureNetwork(ctx context.Context) error {
}

func (p *Provider) destroyNetwork(ctx context.Context) error {
if err := p.dockerClient.NetworkRemove(ctx, p.state.NetworkID); err != nil {
return err
}

return nil
return p.dockerClient.NetworkRemove(ctx, p.state.NetworkID)
}

// openListenerOnFreePort opens the next free port
Expand Down Expand Up @@ -131,7 +127,7 @@ func (p *Provider) nextAvailablePort() (nat.PortBinding, *net.TCPListener, error
}, l, nil
}

func (p *Provider) nextAvailableIp() (string, error) {
func (p *Provider) nextAvailableIP() (string, error) {
p.networkMu.Lock()
p.stateMu.Lock()
defer p.networkMu.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion core/provider/docker/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (p *Provider) CreateTask(ctx context.Context, definition provider.TaskDefin
logger.Debug("creating container", zap.String("name", definition.Name), zap.String("image", definition.Image.Image))

// network map is volatile, so we need to mutex update it
ip, err := p.nextAvailableIp()
ip, err := p.nextAvailableIP()
if err != nil {
return nil, err
}
Expand Down
18 changes: 9 additions & 9 deletions core/provider/docker/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/docker/docker/client"
"github.com/matoous/go-nanoid/v2"
"github.com/skip-mev/petri/core/v2/provider/docker"
"go.uber.org/zap/zaptest"
"sync"
"testing"
"time"

"github.com/skip-mev/petri/core/v2/provider"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

const idAlphabet = "abcdefghijklqmnoqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
Expand All @@ -39,7 +39,7 @@ func setupTest(tb testing.TB, name string) func(testing.TB, string) {

func TestCreateProviderDuplicateNetwork(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand All @@ -58,7 +58,7 @@ func TestCreateProviderDuplicateNetwork(t *testing.T) {

func TestCreateProvider(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand All @@ -79,7 +79,7 @@ func TestCreateProvider(t *testing.T) {

func TestRestoreProvider(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand All @@ -100,7 +100,7 @@ func TestRestoreProvider(t *testing.T) {
}

func TestCreateTask(t *testing.T) {
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)
ctx := context.Background()

Expand Down Expand Up @@ -177,7 +177,7 @@ func TestConcurrentTaskCreation(t *testing.T) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

p, err := docker.CreateProvider(ctx, logger, providerName)
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestConcurrentTaskCreation(t *testing.T) {

func TestProviderSerialization(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)

providerName := gonanoid.MustGenerate(idAlphabet, 10)

Expand Down Expand Up @@ -274,7 +274,7 @@ func TestProviderSerialization(t *testing.T) {

func TestTeardown(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)
p, err := docker.CreateProvider(ctx, logger, providerName)
require.NoError(t, err)
Expand All @@ -299,7 +299,7 @@ func TestTeardown(t *testing.T) {

func TestRestoreTask(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand Down
10 changes: 1 addition & 9 deletions core/provider/docker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ func (t *Task) Destroy(ctx context.Context) error {
return nil
}

//func (t *Task) ensure(_ context.Context) error {
// return nil
//}

func (t *Task) GetExternalAddress(ctx context.Context, port string) (string, error) {
t.provider.logger.Debug("getting external address", zap.String("id", t.state.Id))

Expand Down Expand Up @@ -189,12 +185,8 @@ func (t *Task) GetStatus(ctx context.Context) (provider.TaskStatus, error) {
return provider.TASK_STATUS_UNDEFINED, nil
}

func (t *Task) Initialize(ctx context.Context) error {
return nil
}

func (t *Task) Modify(ctx context.Context, td provider.TaskDefinition) error {
return nil
panic("unimplemented")
}

func (t *Task) RunCommand(ctx context.Context, cmd []string) (string, string, int, error) {
Expand Down
10 changes: 5 additions & 5 deletions core/provider/docker/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestTaskLifecycle(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestTaskLifecycle(t *testing.T) {

func TestTaskExposingPort(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestTaskExposingPort(t *testing.T) {

func TestTaskRunCommand(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestTaskRunCommand(t *testing.T) {

func TestTaskRunCommandWhileStopped(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestTaskRunCommandWhileStopped(t *testing.T) {

func TestTaskReadWriteFile(t *testing.T) {
ctx := context.Background()
logger, _ := zap.NewDevelopment()
logger := zaptest.NewLogger(t)
providerName := gonanoid.MustGenerate(idAlphabet, 10)

teardown := setupTest(t, providerName)
Expand Down
1 change: 0 additions & 1 deletion core/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type Task struct {
}

type TaskI interface {
Initialize(context.Context) error
Start(context.Context) error
Stop(context.Context) error
Destroy(context.Context) error
Expand Down

0 comments on commit 007ace9

Please sign in to comment.