Skip to content

Commit

Permalink
Ensure we push atmost once to the nackCh
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan-bal committed Jul 13, 2024
1 parent bdd707e commit 7b23548
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/xds/xds_server_certificate_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"net"
"strconv"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -110,6 +111,7 @@ func (s) TestServerSideXDS_WithNoCertificateProvidersInBootstrap_Failure(t *test
// Spin up an xDS management server that pushes on a channel when it
// receives a NACK for an LDS response.
nackCh := make(chan struct{}, 1)
nackSeen := atomic.Bool{}
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{
OnStreamRequest: func(_ int64, req *v3discoverypb.DiscoveryRequest) error {
if req.GetTypeUrl() != "type.googleapis.com/envoy.config.listener.v3.Listener" {
Expand All @@ -118,6 +120,12 @@ func (s) TestServerSideXDS_WithNoCertificateProvidersInBootstrap_Failure(t *test
if req.GetErrorDetail() == nil {
return nil
}
// Pushing to the channel more than once will block the xds
// server until a reader clears the channel. So we avoid pushing more
// than once.
if !nackSeen.CompareAndSwap(false, true) {
return nil
}
select {
case nackCh <- struct{}{}:
case <-ctx.Done():
Expand Down Expand Up @@ -237,6 +245,7 @@ func (s) TestServerSideXDS_WithValidAndInvalidSecurityConfiguration(t *testing.T
// Spin up an xDS management server that pushes on a channel when it
// receives a NACK for an LDS response.
nackCh := make(chan struct{}, 1)
nackSeen := atomic.Bool{}
managementServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{
OnStreamRequest: func(_ int64, req *v3discoverypb.DiscoveryRequest) error {
if req.GetTypeUrl() != "type.googleapis.com/envoy.config.listener.v3.Listener" {
Expand All @@ -245,6 +254,12 @@ func (s) TestServerSideXDS_WithValidAndInvalidSecurityConfiguration(t *testing.T
if req.GetErrorDetail() == nil {
return nil
}
// Pushing to the channel more than once will block the xds
// server until a reader clears the channel. So we avoid pushing more
// than once.
if !nackSeen.CompareAndSwap(false, true) {
return nil
}
select {
case nackCh <- struct{}{}:
case <-ctx.Done():
Expand Down

0 comments on commit 7b23548

Please # to comment.