destination: Fix flakey TestEndpointProfileTranslator (#12182)

TestEndpointProfileTranslator could race against the consumer task
so that the final queue insertion would not necessarily fail. The send
buffer has been eliminated to avoid this race.
This commit is contained in:
Oliver Gould 2024-02-29 08:59:44 -08:00 committed by GitHub
parent c831361062
commit e1ab0a2e46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -110,6 +110,10 @@ func (ept *endpointProfileTranslator) Update(address *watcher.Address) error {
}
}
func (ept *endpointProfileTranslator) queueLen() int {
return len(ept.updates)
}
func (ept *endpointProfileTranslator) update(address *watcher.Address) {
var opaquePorts map[uint32]struct{}
if address.Pod != nil {

View File

@ -34,7 +34,7 @@ func TestEndpointProfileTranslator(t *testing.T) {
t.Run("Sends update", func(t *testing.T) {
mockGetProfileServer := &mockDestinationGetProfileServer{
profilesReceived: make(chan *pb.DestinationProfile, 1),
profilesReceived: make(chan *pb.DestinationProfile), // UNBUFFERED
}
log := logging.WithField("test", t.Name())
translator := newEndpointProfileTranslator(
@ -110,9 +110,13 @@ func TestEndpointProfileTranslator(t *testing.T) {
}
}
// The queue should be full and the next update should fail.
t.Logf("Queue length=%d capacity=%d", translator.queueLen(), updateQueueCapacity)
if err := translator.Update(podAddr); err == nil {
t.Fatal("Expected update to fail")
t.Fatalf("Expected update to fail; queue=%d; capacity=%d", translator.queueLen(), updateQueueCapacity)
}
select {
case <-endStream:
default: