[PATCH libnbd 0/2] Golang tests fixes
- 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
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@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
On Sat, Oct 23, 2021 at 11:47:41PM +0300, Nir Soffer wrote:
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".
It may be a situation where executing the test directly causes a different set of default signal handlers to be inherited into the child process than when running under make (never a fun situation to debug or actually prove). Syscalls should only be able to fail with EINTR based on when a program has installed non-default signal handlers, but whether they do that may in turn depend on what they inherit from the parent process. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
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@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
On Sat, Oct 23, 2021 at 11:47:42PM +0300, Nir Soffer wrote:
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@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. */ }
ACK series Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
participants (3)
-
Eric Blake -
Nir Soffer -
Richard W.M. Jones