diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-03-22 16:14:11 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-04-03 08:32:46 +0900 |
commit | 9f93acce2c7e4a7e878179acf2e6e64257767b9c (patch) | |
tree | 6f97d1dd6fa0fe6b1714ac0d04cf736c4f1f8752 | |
parent | b05e13b4951858524ce81a532c0fa8e2a42b88ba (diff) |
bgp_race_test: Unit test to detect data races
This patch adds UT file to detect data races when serializing BGP UPDATE
messages.
Example of Usage:
$ go test -race github.com/osrg/gobgp/packet/bgp -run ^Test_RaceCondition$
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | packet/bgp/bgp_race_test.go | 46 |
2 files changed, 47 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml index 48b6f446..808c1143 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ _unittest: &_unittest <<: *_dep_ensure script: - go test $(go list ./... | grep -v '/vendor/') + - if [ "$(go env GOARCH)" = "amd64" ]; then go test -race github.com/osrg/gobgp/packet/bgp -run ^Test_RaceCondition$; else echo 'skip'; fi - go build -o ./gobgp/gobgp ./gobgp/ - go build -o ./gobgpd/gobgpd ./gobgpd/ diff --git a/packet/bgp/bgp_race_test.go b/packet/bgp/bgp_race_test.go new file mode 100644 index 00000000..08038200 --- /dev/null +++ b/packet/bgp/bgp_race_test.go @@ -0,0 +1,46 @@ +// Copyright (C) 2018 Nippon Telegraph and Telephone Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build race + +package bgp + +import ( + "testing" + "time" +) + +// Test_RaceCondition detects data races when serialization. +// Currently tests only attributes contained in UPDATE message. +func Test_RaceCondition(t *testing.T) { + m := NewTestBGPUpdateMessage() + updateBody := m.Body.(*BGPUpdate) + + go func(body *BGPUpdate) { + for _, v := range body.WithdrawnRoutes { + v.Serialize() + } + for _, v := range body.PathAttributes { + v.Serialize() + } + for _, v := range body.NLRI { + v.Serialize() + } + }(updateBody) + + time.Sleep(time.Second) + + updateBody.Serialize() +} |