github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/integration/plugin/logging/logging_linux_test.go (about) 1 package logging 2 3 import ( 4 "bufio" 5 "context" 6 "os" 7 "strings" 8 "testing" 9 "time" 10 11 "github.com/Prakhar-Agarwal-byte/moby/api/types" 12 containertypes "github.com/Prakhar-Agarwal-byte/moby/api/types/container" 13 "github.com/Prakhar-Agarwal-byte/moby/integration/internal/container" 14 "github.com/Prakhar-Agarwal-byte/moby/testutil" 15 "github.com/Prakhar-Agarwal-byte/moby/testutil/daemon" 16 "gotest.tools/v3/assert" 17 "gotest.tools/v3/skip" 18 ) 19 20 func TestContinueAfterPluginCrash(t *testing.T) { 21 skip.If(t, testEnv.IsRemoteDaemon, "test requires daemon on the same host") 22 t.Parallel() 23 24 ctx := testutil.StartSpan(baseContext, t) 25 26 d := daemon.New(t) 27 d.StartWithBusybox(ctx, t, "--iptables=false", "--init") 28 defer d.Stop(t) 29 30 client := d.NewClientT(t) 31 createPlugin(ctx, t, client, "test", "close_on_start", asLogDriver) 32 33 ctxT, cancel := context.WithTimeout(ctx, 60*time.Second) 34 defer cancel() 35 assert.Assert(t, client.PluginEnable(ctxT, "test", types.PluginEnableOptions{Timeout: 30})) 36 cancel() 37 defer client.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true}) 38 39 ctxT, cancel = context.WithTimeout(ctx, 60*time.Second) 40 defer cancel() 41 42 id := container.Run(ctxT, t, client, 43 container.WithAutoRemove, 44 container.WithLogDriver("test"), 45 container.WithCmd( 46 "/bin/sh", "-c", "while true; do sleep 1; echo hello; done", 47 ), 48 ) 49 cancel() 50 defer client.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true}) 51 52 // Attach to the container to make sure it's written a few times to stdout 53 attach, err := client.ContainerAttach(ctx, id, containertypes.AttachOptions{Stream: true, Stdout: true}) 54 assert.NilError(t, err) 55 56 chErr := make(chan error, 1) 57 go func() { 58 defer close(chErr) 59 rdr := bufio.NewReader(attach.Reader) 60 for i := 0; i < 5; i++ { 61 _, _, err := rdr.ReadLine() 62 if err != nil { 63 chErr <- err 64 return 65 } 66 } 67 }() 68 69 select { 70 case err := <-chErr: 71 assert.NilError(t, err) 72 case <-time.After(60 * time.Second): 73 t.Fatal("timeout waiting for container i/o") 74 } 75 76 // check daemon logs for "broken pipe" 77 // TODO(@cpuguy83): This is horribly hacky but is the only way to really test this case right now. 78 // It would be nice if there was a way to know that a broken pipe has occurred without looking through the logs. 79 log, err := os.Open(d.LogFileName()) 80 assert.NilError(t, err) 81 scanner := bufio.NewScanner(log) 82 for scanner.Scan() { 83 assert.Assert(t, !strings.Contains(scanner.Text(), "broken pipe")) 84 } 85 }