Skip to content

Commit

Permalink
add test for timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
ainghazal committed Jun 24, 2024
1 parent a4bca29 commit 9a2a1b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
30 changes: 17 additions & 13 deletions internal/experiment/openvpn/openvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,7 @@ func (m *Measurer) connectAndHandshake(
handshakeEvents := handshakeTracer.Trace()
port, _ := strconv.Atoi(endpoint.Port)

var (
tFirst float64
tLast float64
bootstrapTime float64
)

if len(handshakeEvents) > 0 {
tFirst = handshakeEvents[0].AtTime
tLast = handshakeEvents[len(handshakeEvents)-1].AtTime
bootstrapTime = tLast - tFirst
}
t0, t, bootstrapTime := TimestampsFromHandshake(handshakeEvents)

return &SingleConnection{
TCPConnect: trace.FirstTCPConnectOrNil(),
Expand All @@ -182,15 +172,29 @@ func (m *Measurer) connectAndHandshake(
Auth: openvpnConfig.OpenVPNOptions().Auth,
Compression: string(openvpnConfig.OpenVPNOptions().Compress),
},
T0: tFirst,
T: tLast,
T0: t0,
T: t,
Tags: []string{},
TransactionID: index,
},
NetworkEvents: handshakeEvents,
}
}

func TimestampsFromHandshake(events []*vpntracex.Event) (float64, float64, float64) {
var (
t0 float64
t float64
duration float64
)
if len(events) > 0 {
t0 = events[0].AtTime
t = events[len(events)-1].AtTime
duration = t - t0
}
return t0, t, duration
}

// FetchProviderCredentials will extract credentials from the configuration we gathered for a given provider.
func (m *Measurer) FetchProviderCredentials(
ctx context.Context,
Expand Down
15 changes: 15 additions & 0 deletions internal/experiment/openvpn/openvpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,18 @@ func TestSuccess(t *testing.T) {
t.Fatal(err)
}
}

func TestTimestampsFromHandshake(t *testing.T) {
events := []*vpntracex.Event{{AtTime: 0}, {AtTime: 1}, {AtTime: 2}}
t0, tlast, duration := openvpn.TimestampsFromHandshake(events)
if t0 != 0 {
t.Fatal("expected t0 == 0")
}
if tlast != 2.0 {
t.Fatal("expected t0 == 2")
}
if duration != 2 {
t.Fatal("expected duration == 2")
}

}

0 comments on commit 9a2a1b6

Please sign in to comment.