From fb900b8be2848dd8c2e38cfc430b2c209a2900c1 Mon Sep 17 00:00:00 2001 From: Alexander Lais Date: Fri, 30 Jun 2023 15:53:51 +0200 Subject: [PATCH] test(integration): measure the time of the last captured packet, not write This decouples the test from disk throughputs for larger files. Reducing the overall capture time to 1s also helps not capturing gigabytes of data on loopback. --- src/pcap/test/integration/agent_api_client.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/pcap/test/integration/agent_api_client.go b/src/pcap/test/integration/agent_api_client.go index 0cfdc400..0f68e724 100644 --- a/src/pcap/test/integration/agent_api_client.go +++ b/src/pcap/test/integration/agent_api_client.go @@ -416,22 +416,27 @@ var _ = Describe("Using LocalResolver", func() { SnapLen: 65000, } + var stop time.Time go func() { - time.Sleep(5 * time.Second) + time.Sleep(1 * time.Second) GinkgoWriter.Println("sending Stop") + stop = time.Now().UTC() client.StopRequest() }() err = client.ProcessCapture(ctx, endpointRequest, captureOptions, cancel) Expect(err).To(BeNil()) validateAge := func(packets []gopacket.Packet) { - maxAge := 10 * time.Second + maxAge := 5 * time.Second Expect(packets).ToNot(BeEmpty()) - firstTimestamp := packets[0].Metadata().Timestamp - Expect(firstTimestamp).ToNot(BeNil()) - delta := time.Since(firstTimestamp) - Expect(delta).To(BeNumerically("<", maxAge), "Expected %s to be %s before %s", firstTimestamp, maxAge, time.Now()) + lastTimestamp := packets[len(packets)-1].Metadata().Timestamp + Expect(lastTimestamp).ToNot(BeNil()) + delta := lastTimestamp.Sub(stop) + logger.Sugar().Infof("Captured %d packets. Last timestamp: %v, %v after stop command", len(packets), lastTimestamp, delta) + Expect(delta).To(BeNumerically("<", maxAge), "Expected %s to be up to %s after %s", lastTimestamp, maxAge, stop) + Expect(delta).To(BeNumerically(">", 0), "Expected delay of stop command and last packet to be > 0") + } validatePcapFile(file, validateAge) })