Skip to content

Commit

Permalink
fix(test): measure the time of the last captured packet, not when fil…
Browse files Browse the repository at this point in the history
…e writing completes

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 committed Jun 30, 2023
1 parent ed1e8a1 commit 1b552d8
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 @@ -421,22 +421,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 1b552d8

Please sign in to comment.