github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/vapp_concurrent_test.go (about)

     1  //go:build concurrent
     2  
     3  /*
     4   * Copyright 2020 VMware, Inc.  All rights reserved.  Licensed under the Apache v2 License.
     5   */
     6  
     7  package govcd
     8  
     9  import (
    10  	"sync"
    11  
    12  	. "gopkg.in/check.v1"
    13  )
    14  
    15  // Test_VAPPRefreshConcurrent is meant to prove and show that structures across
    16  // go-vcloud-director are not thread-safe. Go tests must be run with -race flag
    17  // to capture race condition. It is also guarded by `concurrent` build tag and
    18  // is not run by default.
    19  //
    20  // Run with go test -race -tags "concurrent" -check.vv -check.f Test_VAPPRefreshConcurrent .
    21  func (vcd *TestVCD) Test_VAPPRefreshConcurrent(check *C) {
    22  	var waitgroup sync.WaitGroup
    23  
    24  	if vcd.skipVappTests {
    25  		check.Skip("Skipping test because vapp was not successfully created at setup")
    26  	}
    27  	vapp, err := vcd.vdc.GetVAppByName(vcd.vapp.VApp.Name, false)
    28  	check.Assert(err, IsNil)
    29  
    30  	for counter := 0; counter < 5; counter++ {
    31  		waitgroup.Add(1)
    32  		go func() {
    33  			_ = vapp.Refresh()
    34  			waitgroup.Done()
    35  			// check.Assert(err, IsNil)
    36  		}()
    37  	}
    38  	waitgroup.Wait()
    39  }