Skip to content

Commit d1bfc3a

Browse files
committed
Fix a timing issue on TestCaptureFifoToFile_leak
This test is occasionally failing on my host. Seems there is a timing issue. containerd/fifo upgrade is required to use fifo.ErrReadClosed. The error was not exported before. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 5f3b54f commit d1bfc3a

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/firecracker-microvm/firecracker-go-sdk
33
go 1.11
44

55
require (
6-
github.com/containerd/fifo v0.0.0-20190816180239-bda0ff6ed73c
6+
github.com/containerd/fifo v0.0.0-20191213151349-ff969a566b00
77
github.com/containernetworking/cni v0.7.2-0.20190807151350-8c6c47d1c7fc
88
github.com/containernetworking/plugins v0.8.5
99
github.com/go-openapi/errors v0.19.3
@@ -18,5 +18,7 @@ require (
1818
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c
1919
github.com/stretchr/testify v1.5.1
2020
github.com/vishvananda/netlink v1.1.0
21-
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f
21+
golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56 // indirect
22+
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449
23+
golang.org/x/tools v0.0.0-20190617190820-da514acc4774 // indirect
2224
)

go.sum

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:l
1414
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
1515
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
1616
github.com/buger/jsonparser v0.0.0-20180808090653-f4dd9f5a6b44/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
17-
github.com/containerd/fifo v0.0.0-20190816180239-bda0ff6ed73c h1:KFbqHhDeaHM7IfFtXHfUHMDaUStpM2YwBR+iJCIOsKk=
18-
github.com/containerd/fifo v0.0.0-20190816180239-bda0ff6ed73c/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI=
17+
github.com/containerd/fifo v0.0.0-20191213151349-ff969a566b00 h1:lsjC5ENBl+Zgf38+B0ymougXFp0BaubeIVETltYZTQw=
18+
github.com/containerd/fifo v0.0.0-20191213151349-ff969a566b00/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0=
1919
github.com/containernetworking/cni v0.7.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
2020
github.com/containernetworking/cni v0.7.2-0.20190807151350-8c6c47d1c7fc h1:zUNdrf9w09mWodVhZ9hX4Yk4Uu84n/OgdfPattAwwt8=
2121
github.com/containernetworking/cni v0.7.2-0.20190807151350-8c6c47d1c7fc/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
@@ -145,6 +145,7 @@ github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a h1:KfNOeFvoAssuZLT7Int
145145
github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
146146
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
147147
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
148+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
148149
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
149150
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
150151
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -206,6 +207,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
206207
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
207208
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f h1:25KHgbfyiSm6vwQLbM3zZIe1v9p/3ea4Rz+nnM5K/i4=
208209
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
210+
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 h1:gSbV7h1NRL2G1xTg/owz62CST1oJBmxy4QpMMregXVQ=
211+
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
209212
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
210213
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
211214
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=

machine_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"testing"
3333
"time"
3434

35+
"github.com/containerd/fifo"
3536
"github.com/sirupsen/logrus"
3637
"github.com/stretchr/testify/assert"
3738
"github.com/stretchr/testify/require"
@@ -1095,8 +1096,14 @@ func TestCaptureFifoToFile_leak(t *testing.T) {
10951096
// Waiting the channel to make sure that the contents of the FIFO has been copied
10961097
copyErr := <-done
10971098

1098-
assert.Contains(t, copyErr.Error(), `file already closed`, "error")
1099-
assert.Contains(t, loggerBuffer.String(), `file already closed`, "log")
1099+
if copyErr == fifo.ErrReadClosed {
1100+
// If the fifo package is aware about that the fifo is closed, we can get the error below.
1101+
assert.Contains(t, loggerBuffer.String(), fifo.ErrReadClosed.Error(), "log")
1102+
} else {
1103+
// If not, the error would be something like "read /proc/self/fd/9: file already closed"
1104+
assert.Contains(t, copyErr.Error(), `file already closed`, "error")
1105+
assert.Contains(t, loggerBuffer.String(), `file already closed`, "log")
1106+
}
11001107
}
11011108

11021109
// Replace filesystem-unsafe characters (such as /) which are often seen in Go's test names

0 commit comments

Comments
 (0)