Skip to content

Commit

Permalink
eni/node_manager_test: Add set up and tear down
Browse files Browse the repository at this point in the history
In this test suite, the `metricsapi` is global variable which is shared
among all the `Test*` functions. It is possible that it becomes polluted
over time during test execution.

This is an attempt to resolve the following:

```
FAIL: node_manager_test.go:563: ENISuite.TestNodeManagerManyNodes
node_manager_test.go:602:

    c.Errorf("Node %s allocation mismatch. expected: %d allocated: %d", s.name, minAllocate, node.Stats().AvailableIPs)

... Error: Node node53 allocation mismatch. expected: 10 allocated: 18

node_manager_test.go:602:

    c.Errorf("Node %s allocation mismatch. expected: %d allocated: %d", s.name, minAllocate, node.Stats().AvailableIPs)

... Error: Node node59 allocation mismatch. expected: 10 allocated: 18

node_manager_test.go:617:
    c.Assert(metricsapi.AllocatedIPs("available"), check.Equals, numNodes*minAllocate)
... obtained int = 1016
... expected int = 1000

...
OOPS: 17 passed, 1 FAILED
--- FAIL: Test (2.60s)
FAIL
coverage: 4.3% of statements in ./...

FAIL	github.com/cilium/cilium/pkg/aws/eni	2.684s
FAIL

Makefile:204: recipe for target 'unit-tests' failed
make: *** [unit-tests] Error 1
The command "./.travis/build.sh" exited with 2.
```

Signed-off-by: Chris Tarazi <chris@isovalent.com>
  • Loading branch information
christarazi authored and aanm committed May 27, 2020
1 parent 9ded76e commit 9168268
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/aws/eni/node_manager_test.go
Expand Up @@ -64,6 +64,14 @@ var (
metricsapi = metricsmock.NewMockMetrics()
)

func (e *ENISuite) SetUpTest(c *check.C) {
metricsapi = metricsmock.NewMockMetrics()
}

func (e *ENISuite) TearDownTest(c *check.C) {
metricsapi = nil
}

func (e *ENISuite) TestGetNodeNames(c *check.C) {
ec2api := ec2mock.NewAPI([]*ipamTypes.Subnet{testSubnet}, []*ipamTypes.VirtualNetwork{testVpc}, testSecurityGroups)
instances := NewInstancesManager(ec2api, nil)
Expand Down

0 comments on commit 9168268

Please sign in to comment.