git » systemd » commit 148d444

test: Close sockets opened for testing

author Alberto Bertogli
2020-05-28 23:44:32 UTC
committer Alberto Bertogli
2020-05-28 23:44:32 UTC
parent 7cdf949a210c6e6847824168c6a16eabec3a2490

test: Close sockets opened for testing

This patch makes the tests close the sockets that are opened for
testing. This has no impact in the test outcome, but it can make some
things easier to troubleshoot.

systemd_test.go +5 -0

diff --git a/systemd_test.go b/systemd_test.go
index 5e7686d..3c9099c 100644
--- a/systemd_test.go
+++ b/systemd_test.go
@@ -44,6 +44,7 @@ func TestEmptyEnvironment(t *testing.T) {
 func TestBadEnvironment(t *testing.T) {
 	// Create a listener so we have something to reference.
 	l := newListener(t)
+	defer l.Close()
 	firstFD = listenerFd(t, l)
 
 	ourPID := strconv.Itoa(os.Getpid())
@@ -176,6 +177,7 @@ func sameAddr(a, b net.Addr) bool {
 
 func TestOneSocket(t *testing.T) {
 	l := newListener(t)
+	defer l.Close()
 	firstFD = listenerFd(t, l)
 
 	setenv(strconv.Itoa(os.Getpid()), "1", "name")
@@ -238,6 +240,8 @@ func TestManySockets(t *testing.T) {
 		l1 = newListener(t)
 		f0 = listenerFd(t, l0)
 		f1 = listenerFd(t, l1)
+		defer l0.Close()
+		defer l1.Close()
 		t.Logf("Looping for FDs: %d %d", f0, f1)
 	}
 
@@ -329,6 +333,7 @@ func TestManySockets(t *testing.T) {
 
 func TestListen(t *testing.T) {
 	orig := newListener(t)
+	defer orig.Close()
 	firstFD = listenerFd(t, orig)
 	setenv(strconv.Itoa(os.Getpid()), "1", "name")