github.com/osrg/gobgp@v2.0.0+incompatible/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 // +build race 17 18 package bgp 19 20 import ( 21 "testing" 22 "time" 23 ) 24 25 // Test_RaceCondition detects data races when serialization. 26 // Currently tests only attributes contained in UPDATE message. 27 func Test_RaceCondition(t *testing.T) { 28 m := NewTestBGPUpdateMessage() 29 updateBody := m.Body.(*BGPUpdate) 30 31 go func(body *BGPUpdate) { 32 for _, v := range body.WithdrawnRoutes { 33 v.Serialize() 34 } 35 for _, v := range body.PathAttributes { 36 v.Serialize() 37 } 38 for _, v := range body.NLRI { 39 v.Serialize() 40 } 41 }(updateBody) 42 43 time.Sleep(time.Second) 44 45 updateBody.Serialize() 46 }