github.com/cilium/cilium@v1.16.2/pkg/endpoint/test_utils.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package endpoint 5 6 import ( 7 "github.com/cilium/cilium/pkg/identity" 8 "github.com/cilium/cilium/pkg/time" 9 ) 10 11 // WaitForIdentity waits for up to timeoutDuration amount of time for the 12 // endpoint to have an identity. If the timeout is reached, returns nil. 13 func (e *Endpoint) WaitForIdentity(timeoutDuration time.Duration) *identity.Identity { 14 timeout := time.NewTimer(timeoutDuration) 15 defer timeout.Stop() 16 tick := time.NewTicker(200 * time.Millisecond) 17 defer tick.Stop() 18 var secID *identity.Identity 19 for { 20 select { 21 case <-timeout.C: 22 return nil 23 case <-tick.C: 24 e.unconditionalRLock() 25 secID = e.SecurityIdentity 26 e.runlock() 27 if secID != nil { 28 return secID 29 } 30 } 31 } 32 }