Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Acquire same VLAN in concurrency test #883

Closed
rmotitsuki opened this issue Mar 7, 2019 · 0 comments
Closed

Acquire same VLAN in concurrency test #883

rmotitsuki opened this issue Mar 7, 2019 · 0 comments
Assignees

Comments

@rmotitsuki
Copy link
Member

I was trying to force an Error to acquire Link VLANs and I ended acquiring the same VLAN number for multiple requests.
First I used a test_concurrently decorator to create a unit test.
I added a time.sleep(0.0001) between get_next_available_tag and use_tag to force a delay.

    def test_vlans(self):
        switch_a = Switch('00:00:00:00:00:01')
        switch_b = Switch('00:00:00:00:00:02')
        endpoint_a = Interface('eth0', 1, switch_a)
        endpoint_b = Interface('eth1', 2, switch_b)
        linkA = Link(endpoint_a, endpoint_b)

        @test_concurrently(10)
        def toggle_call_your_method_here():
            # perform the code you want to test here; it must be thread-safe
            vlan = linkA.get_next_available_tag()
            time.sleep(0.0001)
            linkA.use_tag(vlan)
            print('Link %s using %s vlan' % (linkA, vlan.value))

        toggle_call_your_method_here()

The result was:

Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 1 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 2 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 3 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 4 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 4 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 5 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 5 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 6 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 5 vlan
Link <kytos.core.link.Link object at 0x7f9a3def3be0> using 6 vlan
@rmotitsuki rmotitsuki self-assigned this Mar 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant