MCPcopy
hub / github.com/keploy/keploy / effectiveStreamMockWindow

Function effectiveStreamMockWindow

pkg/service/replay/utils.go:486–504  ·  view source on GitHub ↗

effectiveStreamMockWindow calculates the effective time window for streaming mocks. It returns the start time (request timestamp) and end time (anchor + timeout), where anchor is the later of request/response timestamps (falling back to time.Now). The timeout is calculated using pkg.ComputeStreaming

(tc *models.TestCase, defaultAPITimeout uint64)

Source from the content-addressed store, hash-verified

484// where anchor is the later of request/response timestamps (falling back to time.Now).
485// The timeout is calculated using pkg.ComputeStreamingTimeoutSeconds which considers the test case's timeout configuration.
486func effectiveStreamMockWindow(tc *models.TestCase, defaultAPITimeout uint64) (time.Time, time.Time) {
487 if tc == nil {
488 return time.Time{}, time.Time{}
489 }
490
491 reqTs := tc.HTTPReq.Timestamp
492 respTs := tc.HTTPResp.Timestamp
493 timeoutSeconds := pkg.ComputeStreamingTimeoutSeconds(tc, defaultAPITimeout)
494
495 anchor := reqTs
496 if anchor.IsZero() || (!respTs.IsZero() && respTs.After(anchor)) {
497 anchor = respTs
498 }
499 if anchor.IsZero() {
500 anchor = time.Now().UTC()
501 }
502
503 return reqTs, anchor.Add(time.Duration(timeoutSeconds) * time.Second)
504}
505
506func timeWithUnits(duration time.Duration) string {
507 if duration.Seconds() < 1 {

Callers 2

RunTestSetMethod · 0.85

Calls 3

IsZeroMethod · 0.80
AddMethod · 0.80

Tested by 1