github.com/TugasAkhir-QUIC/quic-go@v0.0.2-0.20240215011318-d20e25a9054c/connection_timer_test.go (about)

     1  package quic
     2  
     3  import (
     4  	"time"
     5  
     6  	. "github.com/onsi/ginkgo/v2"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  func (t *connectionTimer) Deadline() time.Time { return t.timer.Deadline() }
    11  
    12  var _ = Describe("Timer", func() {
    13  	It("sets an idle timeout", func() {
    14  		now := time.Now()
    15  		t := newTimer()
    16  		t.SetTimer(now.Add(time.Hour), time.Time{}, time.Time{}, time.Time{})
    17  		Expect(t.Deadline()).To(Equal(now.Add(time.Hour)))
    18  	})
    19  
    20  	It("sets an ACK timer", func() {
    21  		now := time.Now()
    22  		t := newTimer()
    23  		t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
    24  		Expect(t.Deadline()).To(Equal(now.Add(time.Minute)))
    25  	})
    26  
    27  	It("sets a loss timer", func() {
    28  		now := time.Now()
    29  		t := newTimer()
    30  		t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), now.Add(time.Second), time.Time{})
    31  		Expect(t.Deadline()).To(Equal(now.Add(time.Second)))
    32  	})
    33  
    34  	It("sets a pacing timer", func() {
    35  		now := time.Now()
    36  		t := newTimer()
    37  		t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), now.Add(time.Second), now.Add(time.Millisecond))
    38  		Expect(t.Deadline()).To(Equal(now.Add(time.Millisecond)))
    39  	})
    40  
    41  	It("doesn't reset to an earlier time", func() {
    42  		now := time.Now()
    43  		t := newTimer()
    44  		t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
    45  		Expect(t.Deadline()).To(Equal(now.Add(time.Minute)))
    46  		t.SetRead()
    47  
    48  		t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
    49  		Expect(t.Deadline()).To(Equal(now.Add(time.Hour)))
    50  	})
    51  
    52  	It("allows the pacing timer to be set to send immediately", func() {
    53  		now := time.Now()
    54  		t := newTimer()
    55  		t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, time.Time{})
    56  		Expect(t.Deadline()).To(Equal(now.Add(time.Minute)))
    57  		t.SetRead()
    58  
    59  		t.SetTimer(now.Add(time.Hour), now.Add(time.Minute), time.Time{}, deadlineSendImmediately)
    60  		Expect(t.Deadline()).To(Equal(deadlineSendImmediately))
    61  	})
    62  })