Skip to content

Commit

Permalink
test(integration): measure the time of the last captured packet, not …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
peanball authored and maxmoehl committed Jul 19, 2023
1 parent 2148b0e commit fb900b8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/pcap/test/integration/agent_api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit fb900b8

Please sign in to comment.