-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Thomas Haller <[email protected]> Signed-off-by: Thomas Haller <[email protected]>
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package utils | ||
|
||
import ( | ||
"sync/atomic" | ||
"time" | ||
|
||
mocks_utils "github.com/k8snetworkplumbingwg/sriov-cni/pkg/utils/mocks" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/vishvananda/netlink" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var _ = Describe("Packets", func() { | ||
|
||
Context("WaitForCarrier", func() { | ||
It("should wait until the link has IFF_UP flag", func() { | ||
DeferCleanup(func(old NetlinkManager) { netLinkLib = old }, netLinkLib) | ||
|
||
mockedNetLink := &mocks_utils.NetlinkManager{} | ||
netLinkLib = mockedNetLink | ||
|
||
rawFlagsAtomic := new(uint32) | ||
*rawFlagsAtomic = unix.IFF_UP | ||
|
||
fakeLink := &FakeLink{LinkAttrs: netlink.LinkAttrs{ | ||
Index: 1000, | ||
Name: "dummylink", | ||
RawFlags: atomic.LoadUint32(rawFlagsAtomic), | ||
}} | ||
|
||
mockedNetLink.On("LinkByName", "dummylink").Return(fakeLink, nil).Run(func(args mock.Arguments) { | ||
fakeLink.RawFlags = atomic.LoadUint32(rawFlagsAtomic) | ||
}) | ||
|
||
hasCarrier := make(chan bool) | ||
go func() { | ||
hasCarrier <- WaitForCarrier("dummylink", 5*time.Second) | ||
}() | ||
|
||
Consistently(hasCarrier, "100ms").ShouldNot(Receive()) | ||
|
||
go func() { | ||
atomic.StoreUint32(rawFlagsAtomic, unix.IFF_UP|unix.IFF_RUNNING) | ||
}() | ||
|
||
Eventually(hasCarrier, "300ms").Should(Receive()) | ||
}) | ||
}) | ||
}) |