@@ -61,7 +61,7 @@ func sendXDSRespWithVersion(ch chan<- *fakeserver.Response, respWithoutVersion *
6161
6262// startXDS calls watch to send the first request. It then sends a good response
6363// and checks for ack.
64- func startXDS (t * testing.T , xdsname string , v2c * v2Client , reqChan * testutils.Channel , req * xdspb.DiscoveryRequest ) * testutils.Channel {
64+ func startXDS (t * testing.T , xdsname string , v2c * v2Client , reqChan * testutils.Channel , req * xdspb.DiscoveryRequest , preVersion string , preNonce string ) * testutils.Channel {
6565 callbackCh := testutils .NewChannel ()
6666 switch xdsname {
6767 case "LDS" :
@@ -86,7 +86,7 @@ func startXDS(t *testing.T, xdsname string, v2c *v2Client, reqChan *testutils.Ch
8686 })
8787 }
8888
89- if err := compareXDSRequest (reqChan , req , "" , "" ); err != nil {
89+ if err := compareXDSRequest (reqChan , req , preVersion , preNonce ); err != nil {
9090 t .Fatalf ("Failed to receive %s request: %v" , xdsname , err )
9191 }
9292 t .Logf ("FakeServer received %s request..." , xdsname )
@@ -98,8 +98,8 @@ func startXDS(t *testing.T, xdsname string, v2c *v2Client, reqChan *testutils.Ch
9898//
9999// It also waits and checks that the ack request contains the given version, and
100100// the generated nonce.
101- func sendGoodResp (t * testing.T , xdsname string , fakeServer * fakeserver.Server , version int , goodResp * xdspb.DiscoveryResponse , wantReq * xdspb.DiscoveryRequest , callbackCh * testutils.Channel ) {
102- nonce : = sendXDSRespWithVersion (fakeServer .XDSResponseChan , goodResp , version )
101+ func sendGoodResp (t * testing.T , xdsname string , fakeServer * fakeserver.Server , version int , goodResp * xdspb.DiscoveryResponse , wantReq * xdspb.DiscoveryRequest , callbackCh * testutils.Channel ) ( nonce string ) {
102+ nonce = sendXDSRespWithVersion (fakeServer .XDSResponseChan , goodResp , version )
103103 t .Logf ("Good %s response pushed to fakeServer..." , xdsname )
104104
105105 if err := compareXDSRequest (fakeServer .XDSRequestChan , wantReq , strconv .Itoa (version ), nonce ); err != nil {
@@ -111,6 +111,7 @@ func sendGoodResp(t *testing.T, xdsname string, fakeServer *fakeserver.Server, v
111111 t .Errorf ("Timeout when expecting %s update" , xdsname )
112112 }
113113 t .Logf ("Good %s response callback executed" , xdsname )
114+ return
114115}
115116
116117// sendBadResp sends a bad response with the given version. This response will
@@ -159,16 +160,16 @@ func (s) TestV2ClientAck(t *testing.T) {
159160 t .Log ("Started xds v2Client..." )
160161
161162 // Start the watch, send a good response, and check for ack.
162- cbLDS := startXDS (t , "LDS" , v2c , fakeServer .XDSRequestChan , goodLDSRequest )
163+ cbLDS := startXDS (t , "LDS" , v2c , fakeServer .XDSRequestChan , goodLDSRequest , "" , "" )
163164 sendGoodResp (t , "LDS" , fakeServer , versionLDS , goodLDSResponse1 , goodLDSRequest , cbLDS )
164165 versionLDS ++
165- cbRDS := startXDS (t , "RDS" , v2c , fakeServer .XDSRequestChan , goodRDSRequest )
166+ cbRDS := startXDS (t , "RDS" , v2c , fakeServer .XDSRequestChan , goodRDSRequest , "" , "" )
166167 sendGoodResp (t , "RDS" , fakeServer , versionRDS , goodRDSResponse1 , goodRDSRequest , cbRDS )
167168 versionRDS ++
168- cbCDS := startXDS (t , "CDS" , v2c , fakeServer .XDSRequestChan , goodCDSRequest )
169+ cbCDS := startXDS (t , "CDS" , v2c , fakeServer .XDSRequestChan , goodCDSRequest , "" , "" )
169170 sendGoodResp (t , "CDS" , fakeServer , versionCDS , goodCDSResponse1 , goodCDSRequest , cbCDS )
170171 versionCDS ++
171- cbEDS := startXDS (t , "EDS" , v2c , fakeServer .XDSRequestChan , goodEDSRequest )
172+ cbEDS := startXDS (t , "EDS" , v2c , fakeServer .XDSRequestChan , goodEDSRequest , "" , "" )
172173 sendGoodResp (t , "EDS" , fakeServer , versionEDS , goodEDSResponse1 , goodEDSRequest , cbEDS )
173174 versionEDS ++
174175
@@ -205,7 +206,7 @@ func (s) TestV2ClientAckFirstIsNack(t *testing.T) {
205206 t .Log ("Started xds v2Client..." )
206207
207208 // Start the watch, send a good response, and check for ack.
208- cbLDS := startXDS (t , "LDS" , v2c , fakeServer .XDSRequestChan , goodLDSRequest )
209+ cbLDS := startXDS (t , "LDS" , v2c , fakeServer .XDSRequestChan , goodLDSRequest , "" , "" )
209210
210211 nonce := sendXDSRespWithVersion (fakeServer .XDSResponseChan , & xdspb.DiscoveryResponse {
211212 Resources : []* anypb.Any {{}},
@@ -237,15 +238,16 @@ func (s) TestV2ClientAckNackAfterNewWatch(t *testing.T) {
237238 t .Log ("Started xds v2Client..." )
238239
239240 // Start the watch, send a good response, and check for ack.
240- cbLDS := startXDS (t , "LDS" , v2c , fakeServer .XDSRequestChan , goodLDSRequest )
241- sendGoodResp (t , "LDS" , fakeServer , versionLDS , goodLDSResponse1 , goodLDSRequest , cbLDS )
242- versionLDS ++
241+ cbLDS := startXDS (t , "LDS" , v2c , fakeServer .XDSRequestChan , goodLDSRequest , "" , "" )
242+ nonce := sendGoodResp (t , "LDS" , fakeServer , versionLDS , goodLDSResponse1 , goodLDSRequest , cbLDS )
243243
244- // Start a new watch.
245- cbLDS = startXDS (t , "LDS" , v2c , fakeServer .XDSRequestChan , goodLDSRequest )
244+ // Start a new watch. The version in the new request should be the version
245+ // from the previous response, thus versionLDS before ++.
246+ cbLDS = startXDS (t , "LDS" , v2c , fakeServer .XDSRequestChan , goodLDSRequest , strconv .Itoa (versionLDS ), nonce )
247+ versionLDS ++
246248
247249 // This is an invalid response after the new watch.
248- nonce : = sendXDSRespWithVersion (fakeServer .XDSResponseChan , & xdspb.DiscoveryResponse {
250+ nonce = sendXDSRespWithVersion (fakeServer .XDSResponseChan , & xdspb.DiscoveryResponse {
249251 Resources : []* anypb.Any {{}},
250252 TypeUrl : ldsURL ,
251253 }, versionLDS )
0 commit comments