- Retry interrupted syscall.Select() - Verify LibnbdError.Errno value Nir Soffer (2): golang/tests: Retry syscall.Select on EINTR golang/tests: Test expected Errno .../src/libguestfs.org/libnbd/libnbd_590_aio_copy_test.go | 7 ++++++- golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) -- 2.31.1
Nir Soffer
2021-Oct-23 20:47 UTC
[Libguestfs] [PATCH libnbd 1/2] golang/tests: Retry syscall.Select on EINTR
Go syscall package does not handle EINTR like higher level packages, so we need to handle it when using syscall.Select(). The test always fails when running: $ GOLANG=go pkg=libguestfs.org/libnbd ./run-tests.sh ... === RUN Test590AioCopy libnbd_590_aio_copy_test.go:160: select: interrupted system call Strangely, it never fails when running "make check". Signed-off-by: Nir Soffer <nsoffer at redhat.com> --- .../src/libguestfs.org/libnbd/libnbd_590_aio_copy_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/golang/src/libguestfs.org/libnbd/libnbd_590_aio_copy_test.go b/golang/src/libguestfs.org/libnbd/libnbd_590_aio_copy_test.go index d566e6b..ed7aed4 100644 --- a/golang/src/libguestfs.org/libnbd/libnbd_590_aio_copy_test.go +++ b/golang/src/libguestfs.org/libnbd/libnbd_590_aio_copy_test.go @@ -155,7 +155,12 @@ func asynch_copy(t *testing.T, src *Libnbd, dst *Libnbd) { if dir_is_write(dst) { fdset_set(&wfds, dfd) } - _, err = syscall.Select(nfd, &rfds, &wfds, nil, nil) + for { + _, err = syscall.Select(nfd, &rfds, &wfds, nil, nil) + if err != syscall.EINTR { + break + } + } if err != nil { t.Fatalf("select: %s", err) } -- 2.31.1
Nir Soffer
2021-Oct-23 20:47 UTC
[Libguestfs] [PATCH libnbd 2/2] golang/tests: Test expected Errno
Use type assertion[1] to convert err to the concrete LibnbdError so we can verify the expected Errno. The assertion will panic if err is not a LibnbdError. [1] https://tour.golang.org/methods/15 Signed-off-by: Nir Soffer <nsoffer at redhat.com> --- golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go b/golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go index 27540ce..0f81e76 100644 --- a/golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go +++ b/golang/src/libguestfs.org/libnbd/libnbd_610_error_test.go @@ -18,7 +18,7 @@ package libnbd -import "fmt" +import "syscall" import "testing" func Test610Error(t *testing.T) { @@ -34,8 +34,7 @@ func Test610Error(t *testing.T) { err = h.Pread(buf, 0, nil) if err == nil { t.Fatalf("expected an error from operation") + } else if err.(*LibnbdError).Errno != syscall.ENOTCONN { + t.Fatalf("unexpected error: %s", err) } - fmt.Printf("error = %s\n", err) - /* XXX We expect the errno to be ENOTCONN, but I couldn't work - out how to test it. */ } -- 2.31.1