github.com/tumi8/quic-go@v0.37.4-tum/logging/multiplex_test.go (about) 1 package logging 2 3 import ( 4 "errors" 5 "net" 6 "time" 7 8 "github.com/tumi8/quic-go/noninternal/protocol" 9 "github.com/tumi8/quic-go/noninternal/wire" 10 11 . "github.com/onsi/ginkgo/v2" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("Tracing", func() { 16 Context("Tracer", func() { 17 It("returns a nil tracer if no tracers are passed in", func() { 18 Expect(NewMultiplexedTracer()).To(BeNil()) 19 }) 20 21 It("returns the raw tracer if only one tracer is passed in", func() { 22 tr := NewMockTracer(mockCtrl) 23 tracer := NewMultiplexedTracer(tr) 24 Expect(tracer).To(BeAssignableToTypeOf(&MockTracer{})) 25 }) 26 27 Context("tracing events", func() { 28 var ( 29 tracer Tracer 30 tr1, tr2 *MockTracer 31 ) 32 33 BeforeEach(func() { 34 tr1 = NewMockTracer(mockCtrl) 35 tr2 = NewMockTracer(mockCtrl) 36 tracer = NewMultiplexedTracer(tr1, tr2) 37 }) 38 39 It("traces the PacketSent event", func() { 40 remote := &net.UDPAddr{IP: net.IPv4(4, 3, 2, 1)} 41 hdr := &Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})} 42 f := &MaxDataFrame{MaximumData: 1337} 43 tr1.EXPECT().SentPacket(remote, hdr, ByteCount(1024), []Frame{f}) 44 tr2.EXPECT().SentPacket(remote, hdr, ByteCount(1024), []Frame{f}) 45 tracer.SentPacket(remote, hdr, 1024, []Frame{f}) 46 }) 47 48 It("traces the PacketSent event", func() { 49 remote := &net.UDPAddr{IP: net.IPv4(4, 3, 2, 1)} 50 src := ArbitraryLenConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} 51 dest := ArbitraryLenConnectionID{1, 2, 3, 4} 52 versions := []VersionNumber{1, 2, 3} 53 tr1.EXPECT().SentVersionNegotiationPacket(remote, dest, src, versions) 54 tr2.EXPECT().SentVersionNegotiationPacket(remote, dest, src, versions) 55 tracer.SentVersionNegotiationPacket(remote, dest, src, versions) 56 }) 57 58 It("traces the PacketDropped event", func() { 59 remote := &net.UDPAddr{IP: net.IPv4(4, 3, 2, 1)} 60 tr1.EXPECT().DroppedPacket(remote, PacketTypeRetry, ByteCount(1024), PacketDropDuplicate) 61 tr2.EXPECT().DroppedPacket(remote, PacketTypeRetry, ByteCount(1024), PacketDropDuplicate) 62 tracer.DroppedPacket(remote, PacketTypeRetry, 1024, PacketDropDuplicate) 63 }) 64 }) 65 }) 66 67 Context("Connection Tracer", func() { 68 var ( 69 tracer ConnectionTracer 70 tr1 *MockConnectionTracer 71 tr2 *MockConnectionTracer 72 ) 73 74 BeforeEach(func() { 75 tr1 = NewMockConnectionTracer(mockCtrl) 76 tr2 = NewMockConnectionTracer(mockCtrl) 77 tracer = NewMultiplexedConnectionTracer(tr1, tr2) 78 }) 79 80 It("trace the ConnectionStarted event", func() { 81 local := &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4)} 82 remote := &net.UDPAddr{IP: net.IPv4(4, 3, 2, 1)} 83 dest := protocol.ParseConnectionID([]byte{1, 2, 3, 4}) 84 src := protocol.ParseConnectionID([]byte{4, 3, 2, 1}) 85 tr1.EXPECT().StartedConnection(local, remote, src, dest) 86 tr2.EXPECT().StartedConnection(local, remote, src, dest) 87 tracer.StartedConnection(local, remote, src, dest) 88 }) 89 90 It("traces the ClosedConnection event", func() { 91 e := errors.New("test err") 92 tr1.EXPECT().ClosedConnection(e) 93 tr2.EXPECT().ClosedConnection(e) 94 tracer.ClosedConnection(e) 95 }) 96 97 It("traces the SentTransportParameters event", func() { 98 tp := &wire.TransportParameters{InitialMaxData: 1337} 99 tr1.EXPECT().SentTransportParameters(tp) 100 tr2.EXPECT().SentTransportParameters(tp) 101 tracer.SentTransportParameters(tp) 102 }) 103 104 It("traces the ReceivedTransportParameters event", func() { 105 tp := &wire.TransportParameters{InitialMaxData: 1337} 106 tr1.EXPECT().ReceivedTransportParameters(tp) 107 tr2.EXPECT().ReceivedTransportParameters(tp) 108 tracer.ReceivedTransportParameters(tp) 109 }) 110 111 It("traces the RestoredTransportParameters event", func() { 112 tp := &wire.TransportParameters{InitialMaxData: 1337} 113 tr1.EXPECT().RestoredTransportParameters(tp) 114 tr2.EXPECT().RestoredTransportParameters(tp) 115 tracer.RestoredTransportParameters(tp) 116 }) 117 118 It("traces the SentLongHeaderPacket event", func() { 119 hdr := &ExtendedHeader{Header: Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})}} 120 ack := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 10}}} 121 ping := &PingFrame{} 122 tr1.EXPECT().SentLongHeaderPacket(hdr, ByteCount(1337), ack, []Frame{ping}) 123 tr2.EXPECT().SentLongHeaderPacket(hdr, ByteCount(1337), ack, []Frame{ping}) 124 tracer.SentLongHeaderPacket(hdr, 1337, ack, []Frame{ping}) 125 }) 126 127 It("traces the SentShortHeaderPacket event", func() { 128 hdr := &ShortHeader{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})} 129 ack := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 10}}} 130 ping := &PingFrame{} 131 tr1.EXPECT().SentShortHeaderPacket(hdr, ByteCount(1337), ack, []Frame{ping}) 132 tr2.EXPECT().SentShortHeaderPacket(hdr, ByteCount(1337), ack, []Frame{ping}) 133 tracer.SentShortHeaderPacket(hdr, 1337, ack, []Frame{ping}) 134 }) 135 136 It("traces the ReceivedVersionNegotiationPacket event", func() { 137 src := ArbitraryLenConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} 138 dest := ArbitraryLenConnectionID{1, 2, 3, 4} 139 tr1.EXPECT().ReceivedVersionNegotiationPacket(dest, src, []VersionNumber{1337}) 140 tr2.EXPECT().ReceivedVersionNegotiationPacket(dest, src, []VersionNumber{1337}) 141 tracer.ReceivedVersionNegotiationPacket(dest, src, []VersionNumber{1337}) 142 }) 143 144 It("traces the ReceivedRetry event", func() { 145 hdr := &Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})} 146 tr1.EXPECT().ReceivedRetry(hdr) 147 tr2.EXPECT().ReceivedRetry(hdr) 148 tracer.ReceivedRetry(hdr) 149 }) 150 151 It("traces the ReceivedLongHeaderPacket event", func() { 152 hdr := &ExtendedHeader{Header: Header{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})}} 153 ping := &PingFrame{} 154 tr1.EXPECT().ReceivedLongHeaderPacket(hdr, ByteCount(1337), []Frame{ping}) 155 tr2.EXPECT().ReceivedLongHeaderPacket(hdr, ByteCount(1337), []Frame{ping}) 156 tracer.ReceivedLongHeaderPacket(hdr, 1337, []Frame{ping}) 157 }) 158 159 It("traces the ReceivedShortHeaderPacket event", func() { 160 hdr := &ShortHeader{DestConnectionID: protocol.ParseConnectionID([]byte{1, 2, 3})} 161 ping := &PingFrame{} 162 tr1.EXPECT().ReceivedShortHeaderPacket(hdr, ByteCount(1337), []Frame{ping}) 163 tr2.EXPECT().ReceivedShortHeaderPacket(hdr, ByteCount(1337), []Frame{ping}) 164 tracer.ReceivedShortHeaderPacket(hdr, 1337, []Frame{ping}) 165 }) 166 167 It("traces the BufferedPacket event", func() { 168 tr1.EXPECT().BufferedPacket(PacketTypeHandshake, ByteCount(1337)) 169 tr2.EXPECT().BufferedPacket(PacketTypeHandshake, ByteCount(1337)) 170 tracer.BufferedPacket(PacketTypeHandshake, 1337) 171 }) 172 173 It("traces the DroppedPacket event", func() { 174 tr1.EXPECT().DroppedPacket(PacketTypeInitial, ByteCount(1337), PacketDropHeaderParseError) 175 tr2.EXPECT().DroppedPacket(PacketTypeInitial, ByteCount(1337), PacketDropHeaderParseError) 176 tracer.DroppedPacket(PacketTypeInitial, 1337, PacketDropHeaderParseError) 177 }) 178 179 It("traces the UpdatedCongestionState event", func() { 180 tr1.EXPECT().UpdatedCongestionState(CongestionStateRecovery) 181 tr2.EXPECT().UpdatedCongestionState(CongestionStateRecovery) 182 tracer.UpdatedCongestionState(CongestionStateRecovery) 183 }) 184 185 It("traces the UpdatedMetrics event", func() { 186 rttStats := &RTTStats{} 187 rttStats.UpdateRTT(time.Second, 0, time.Now()) 188 tr1.EXPECT().UpdatedMetrics(rttStats, ByteCount(1337), ByteCount(42), 13) 189 tr2.EXPECT().UpdatedMetrics(rttStats, ByteCount(1337), ByteCount(42), 13) 190 tracer.UpdatedMetrics(rttStats, 1337, 42, 13) 191 }) 192 193 It("traces the AcknowledgedPacket event", func() { 194 tr1.EXPECT().AcknowledgedPacket(EncryptionHandshake, PacketNumber(42)) 195 tr2.EXPECT().AcknowledgedPacket(EncryptionHandshake, PacketNumber(42)) 196 tracer.AcknowledgedPacket(EncryptionHandshake, 42) 197 }) 198 199 It("traces the LostPacket event", func() { 200 tr1.EXPECT().LostPacket(EncryptionHandshake, PacketNumber(42), PacketLossReorderingThreshold) 201 tr2.EXPECT().LostPacket(EncryptionHandshake, PacketNumber(42), PacketLossReorderingThreshold) 202 tracer.LostPacket(EncryptionHandshake, 42, PacketLossReorderingThreshold) 203 }) 204 205 It("traces the UpdatedPTOCount event", func() { 206 tr1.EXPECT().UpdatedPTOCount(uint32(88)) 207 tr2.EXPECT().UpdatedPTOCount(uint32(88)) 208 tracer.UpdatedPTOCount(88) 209 }) 210 211 It("traces the UpdatedKeyFromTLS event", func() { 212 tr1.EXPECT().UpdatedKeyFromTLS(EncryptionHandshake, PerspectiveClient) 213 tr2.EXPECT().UpdatedKeyFromTLS(EncryptionHandshake, PerspectiveClient) 214 tracer.UpdatedKeyFromTLS(EncryptionHandshake, PerspectiveClient) 215 }) 216 217 It("traces the UpdatedKey event", func() { 218 tr1.EXPECT().UpdatedKey(KeyPhase(42), true) 219 tr2.EXPECT().UpdatedKey(KeyPhase(42), true) 220 tracer.UpdatedKey(KeyPhase(42), true) 221 }) 222 223 It("traces the DroppedEncryptionLevel event", func() { 224 tr1.EXPECT().DroppedEncryptionLevel(EncryptionHandshake) 225 tr2.EXPECT().DroppedEncryptionLevel(EncryptionHandshake) 226 tracer.DroppedEncryptionLevel(EncryptionHandshake) 227 }) 228 229 It("traces the DroppedKey event", func() { 230 tr1.EXPECT().DroppedKey(KeyPhase(123)) 231 tr2.EXPECT().DroppedKey(KeyPhase(123)) 232 tracer.DroppedKey(123) 233 }) 234 235 It("traces the SetLossTimer event", func() { 236 now := time.Now() 237 tr1.EXPECT().SetLossTimer(TimerTypePTO, EncryptionHandshake, now) 238 tr2.EXPECT().SetLossTimer(TimerTypePTO, EncryptionHandshake, now) 239 tracer.SetLossTimer(TimerTypePTO, EncryptionHandshake, now) 240 }) 241 242 It("traces the LossTimerExpired event", func() { 243 tr1.EXPECT().LossTimerExpired(TimerTypePTO, EncryptionHandshake) 244 tr2.EXPECT().LossTimerExpired(TimerTypePTO, EncryptionHandshake) 245 tracer.LossTimerExpired(TimerTypePTO, EncryptionHandshake) 246 }) 247 248 It("traces the LossTimerCanceled event", func() { 249 tr1.EXPECT().LossTimerCanceled() 250 tr2.EXPECT().LossTimerCanceled() 251 tracer.LossTimerCanceled() 252 }) 253 254 It("traces the Close event", func() { 255 tr1.EXPECT().Close() 256 tr2.EXPECT().Close() 257 tracer.Close() 258 }) 259 }) 260 })