Skip to content

Commit

Permalink
Merge branch 'main' into v1
Browse files Browse the repository at this point in the history
* main:
  fix(compose): remove test volumes (#2712)
  chore(mysql): add missing error check in example (#2707)
  chore: remove unused params from defaultPreCreateHook (#2714)
  docs: improve docs for container methods (#2713)
  chore(registry): disable build log (#2711)
  chore: remove obsolete compose version (#2710)
  chore: improve lifecycle errors (#2708)
  docs: add consistent snippets for network creation (#2703)
  test: add retry on system error test (#2687)
  Redpanda Module: Add option for arbitrary bootstrap config (#2666)
  feat(inbucket): expose POP3 and wait for all ports (#2690)
  fix(wait): data race in test (#2698)
  fix(milvus): racy container setup (#2693)
  fix(mongodb): replica test failures (#2699)
  test: racy port creation in port forwarding tests (#2688)
  fix: port forwarding race condition (#2686)
  • Loading branch information
mdelapenya committed Aug 9, 2024
2 parents 36fff00 + dbc0ba9 commit eaa90db
Show file tree
Hide file tree
Showing 40 changed files with 380 additions and 357 deletions.
23 changes: 6 additions & 17 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -315,28 +314,18 @@ func TestGetLogsFromFailedContainer(t *testing.T) {
// }

c, err := testcontainers.Run(ctx, req)

if err != nil && err.Error() != "failed to start container: container exited with code 0" {
t.Fatal(err)
} else if err == nil {
testcontainers.TerminateContainerOnEnd(t, ctx, c)
t.Fatal("was expecting error starting container")
}
testcontainers.TerminateContainerOnEnd(t, ctx, c)
require.Error(t, err)
require.Contains(t, err.Error(), "container exited with code 0")

logs, logErr := c.Logs(ctx)
if logErr != nil {
t.Fatal(logErr)
}
require.NoError(t, logErr)

b, err := io.ReadAll(logs)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

log := string(b)
if strings.Contains(log, "I was not expecting this") == false {
t.Fatalf("could not find expected log in %s", log)
}
require.Contains(t, log, "I was not expecting this")
}

type errorSubstitutor struct{}
Expand Down
9 changes: 5 additions & 4 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ func (c *DockerContainer) inspectRawContainer(ctx context.Context) (*types.Conta
return &jsonRaw, nil
}

// IsRunning returns true if the container is running, false otherwise.
func (c *DockerContainer) IsRunning() bool {
return c.isRunning
}
Expand Down Expand Up @@ -575,7 +576,7 @@ func (c *DockerContainer) SetTerminationSignal(signal chan bool) {
func (c *DockerContainer) Start(ctx context.Context) error {
err := c.startingHook(ctx)
if err != nil {
return err
return fmt.Errorf("starting hook: %w", err)
}

cli, err := core.NewClient(ctx)
Expand All @@ -585,19 +586,19 @@ func (c *DockerContainer) Start(ctx context.Context) error {
defer cli.Close()

if err := cli.ContainerStart(ctx, c.ID, container.StartOptions{}); err != nil {
return err
return fmt.Errorf("container start: %w", err)
}

err = c.startedHook(ctx)
if err != nil {
return err
return fmt.Errorf("started hook: %w", err)
}

c.isRunning = true

err = c.readiedHook(ctx)
if err != nil {
return err
return fmt.Errorf("readied hook: %w", err)
}

return nil
Expand Down
26 changes: 25 additions & 1 deletion docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,11 @@ func TestDockerProvider_BuildImage_Retries(t *testing.T) {
errReturned: errdefs.NotImplemented(errors.New("unknown method")),
shouldRetry: false,
},
{
name: "no retry on system error",
errReturned: errdefs.System(errors.New("system error")),
shouldRetry: false,
},
{
name: "retry on non-permanent error",
errReturned: errors.New("whoops"),
Expand All @@ -1467,7 +1472,16 @@ func TestDockerProvider_BuildImage_Retries(t *testing.T) {
// give a chance to retry
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()
_, _ = tcimage.Build(ctx, &Request{})
_, err := tcimage.Build(ctx, &Request{
FromDockerfile: FromDockerfile{
Context: filepath.Join(".", "testdata", "retry"),
},
})
if tt.errReturned != nil {
require.Error(t, err)
} else {
require.NoError(t, err)
}

assert.Positive(t, m.imageBuildCount)
assert.Equal(t, tt.shouldRetry, m.imageBuildCount > 1)
Expand Down Expand Up @@ -1501,6 +1515,11 @@ func TestDockerProvider_waitContainerCreation_retries(t *testing.T) {
errReturned: errdefs.NotFound(errors.New("not there yet")),
shouldRetry: true,
},
{
name: "no retry on system error",
errReturned: errdefs.System(errors.New("system error")),
shouldRetry: false,
},
{
name: "retry on non-permanent error",
errReturned: errors.New("whoops"),
Expand Down Expand Up @@ -1561,6 +1580,11 @@ func TestDockerProvider_attemptToPullImage_retries(t *testing.T) {
errReturned: errdefs.NotImplemented(errors.New("unknown method")),
shouldRetry: false,
},
{
name: "no retry on system error",
errReturned: errdefs.System(errors.New("system error")),
shouldRetry: false,
},
{
name: "retry on non-permanent error",
errReturned: errors.New("whoops"),
Expand Down
4 changes: 2 additions & 2 deletions docs/features/creating_networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ It's important to mention that the name of the network is automatically generate
## Usage example

<!--codeinclude-->
[Creating a network](../../network/network_test.go) inside_block:createNetwork
[Creating a network with options](../../network/network_test.go) inside_block:newNetworkWithOptions
[Creating a network](../../network_examples_test.go) inside_block:createNetwork
[Creating a network with options](../../network_examples_test.go) inside_block:newNetworkWithOptions
<!--/codeinclude-->
1 change: 0 additions & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func TerminateContainerOnEnd(tb testing.TB, ctx context.Context, ctr CreatedCont

tb.Cleanup(func() {
if ctr != nil {
tb.Log("terminating container")
require.NoError(tb, ctr.Terminate(ctx))
}
})
Expand Down
2 changes: 1 addition & 1 deletion lifecycle_ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var defaultReadinessHook = func() LifecycleHooks {
dockerContainer.ID[:12], dockerContainer.Image, dockerContainer.WaitingFor,
)
if err := dockerContainer.WaitingFor.WaitUntilReady(ctx, c); err != nil {
return err
return fmt.Errorf("wait until ready: %w", err)
}
}
dockerContainer.isRunning = true
Expand Down
8 changes: 0 additions & 8 deletions modules/compose/compose_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ func (f stackUpOptionFunc) applyToStackUp(o *stackUpOptions) {
f(o)
}

//nolint:unused
type stackDownOptionFunc func(do *api.DownOptions)

//nolint:unused
func (f stackDownOptionFunc) applyToStackDown(do *api.DownOptions) {
f(do)
}

// RunServices is comparable to 'docker compose run' as it only creates a subset of containers
// instead of all services defined by the project
func RunServices(serviceNames ...string) StackUpOption {
Expand Down
Loading

0 comments on commit eaa90db

Please sign in to comment.