wireguard: Fix timeout in unit test
wireguard: Fix timeout in unit test

This commit fixes a deadlock in a unit test which ironically tests for
deadlocks. The unit test in question ensures that the `wireguard.Agent`
`UpdatePeer` method does not create a deadlock if a concurrent IPCache
update is performed.

The previous version of this test wanted to ensure this by taking a
read-lock on the IPCache, which would ensure that only `UpdatePeer`
would make progress (as it also just takes an RLock). However, that
approach could lead to a timeout when `ipCache.Upsert` was invoked
before `wgAgent.UpdatePeer`, as due to the FIFO nature of underlying
mutex implementation, `UpdatePeer` will never obtain an `RLock` if there
is a waiting writer.

This commit addresses this by taking the `wgAgent` lock instead. This
means that `UpdatePeer` will lock the IPCache and then wait for the
`wgAgent` lock to become available. Any concurrent IPCache updates will
also be blocked until `UpdatePeer` has finished as before.

This commit also introduces some additional checks to ensure the spawned
go routines have actually been scheduled. This is still best effort, as
there is easy way to ensure that a certain method is blocked on a
particular mutex.

Signed-off-by: Sebastian Wicki <db043b2055cb3a47b2eb0b5aebf4e114a8c24a5a@isovalent.com>

cilium/cilium,tgraf/cilium,tklauser/cilium,cilium/cilium,tgraf/cilium,michi-covalent/cilium,tklauser/cilium,tklauser/cilium,cilium/cilium,michi-covalent/cilium,michi-covalent/cilium,cilium/cilium,tklauser/cilium,tgraf/cilium,tgraf/cilium,cilium/cilium,michi-covalent/cilium,tgraf/cilium,tgraf/cilium,michi-covalent/cilium,tklauser/cilium