github.com/osrg/gobgp/v3@v3.30.0/pkg/packet/bgp/bgp_race_test.go (about)

     1  // Copyright (C) 2018 Nippon Telegraph and Telephone Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    12  // implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  //go:build race
    17  // +build race
    18  
    19  package bgp
    20  
    21  import (
    22  	"testing"
    23  	"time"
    24  )
    25  
    26  // Test_RaceCondition detects data races when serialization.
    27  // Currently tests only attributes contained in UPDATE message.
    28  func Test_RaceCondition(t *testing.T) {
    29  	m := NewTestBGPUpdateMessage()
    30  	updateBody := m.Body.(*BGPUpdate)
    31  
    32  	go func(body *BGPUpdate) {
    33  		for _, v := range body.WithdrawnRoutes {
    34  			v.Serialize()
    35  		}
    36  		for _, v := range body.PathAttributes {
    37  			v.Serialize()
    38  		}
    39  		for _, v := range body.NLRI {
    40  			v.Serialize()
    41  		}
    42  	}(updateBody)
    43  
    44  	time.Sleep(time.Second)
    45  
    46  	updateBody.Serialize()
    47  }