Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix flaky tests poller tests and simplecache test #606

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/internal/testhelper/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func GetFreePort() uint16 {
}

defer l.Close()
return uint16(l.Addr().(*net.TCPAddr).Port)
return uint16(l.Addr().(*net.TCPAddr).Port) //#nosec G115
}
23 changes: 18 additions & 5 deletions src/pkg/binding/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ var _ = Describe("Poller", func() {
})

It("skips parsing v4 results if CAPI v5 endpoint is unavailable but CAPI is already updated", func() {

apiClient.statusCode <- 404
apiClient.legacyBindings <- legacyResponse{
Results: map[string]struct {
Expand All @@ -394,8 +393,15 @@ var _ = Describe("Poller", func() {
p := binding.NewPoller(apiClient, 100*time.Millisecond, store, legacyStore, metrics, logger)
go p.Poll()

Eventually(store.bindings).Should(BeEmpty())
Eventually(legacyStore.bindings).Should(BeEmpty())
var lastSetBinding []binding.Binding
var lastSetLegacyBinding []binding.LegacyBinding
Eventually(store.bindings).Should(Receive(&lastSetBinding))
Eventually(legacyStore.bindings).Should(Receive(&lastSetLegacyBinding))
Expect(lastSetBinding).To(BeEmpty())
Expect(lastSetLegacyBinding).To(BeEmpty())

Expect(legacyStore.bindings).To(BeEmpty())
Expect(store.bindings).To(BeEmpty())
})

It("does not update the stores if both response codes are bad", func() {
Expand All @@ -405,8 +411,15 @@ var _ = Describe("Poller", func() {
p := binding.NewPoller(apiClient, 100*time.Millisecond, store, legacyStore, metrics, logger)
go p.Poll()

Eventually(store.bindings).Should(BeEmpty())
Eventually(legacyStore.bindings).Should(BeEmpty())
var lastSetBinding []binding.Binding
var lastSetLegacyBinding []binding.LegacyBinding
Eventually(store.bindings).Should(Receive(&lastSetBinding))
Eventually(legacyStore.bindings).Should(Receive(&lastSetLegacyBinding))
Expect(lastSetBinding).To(BeEmpty())
Expect(lastSetLegacyBinding).To(BeEmpty())

Expect(legacyStore.bindings).To(BeEmpty())
Expect(store.bindings).To(BeEmpty())
})

It("tracks the number of bindings returned from CAPI", func() {
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/otelcolclient/otelcolclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (c *Client) addCounterToBatch(e *loggregator_v2.Envelope) {
TimeUnixNano: uint64(e.GetTimestamp()),
Attributes: atts,
Value: &metricspb.NumberDataPoint_AsInt{
AsInt: int64(e.GetCounter().GetTotal()),
AsInt: int64(e.GetCounter().GetTotal()), //#nosec G115
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/plumbing/envelope_averager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewEnvelopeAverager() *EnvelopeAverager {
func (a *EnvelopeAverager) Track(count, size int) {
for {
current := atomic.LoadUint64((*uint64)(&a.storage))
newValue := countAndTotal(current).encodeDelta(uint16(count), uint64(size))
newValue := countAndTotal(current).encodeDelta(uint16(count), uint64(size)) //#nosec G115

if atomic.CompareAndSwapUint64((*uint64)(&a.storage), current, uint64(newValue)) {
return
Expand Down Expand Up @@ -77,7 +77,7 @@ func (u countAndTotal) encodeDelta(count uint16, total uint64) countAndTotal {
}

func (u countAndTotal) decode() (count uint16, total uint64) {
count = uint16((uint64(u) & 0xFFFF000000000000) >> 48)
count = uint16((uint64(u) & 0xFFFF000000000000) >> 48) // #nosec G115
total = (uint64(u) & 0x0000FFFFFFFFFFFF)
return count, total
}
5 changes: 3 additions & 2 deletions src/pkg/simplecache/simplecache_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package simplecache_test

import (
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/simplecache"
"time"

"code.cloudfoundry.org/loggregator-agent-release/src/pkg/simplecache"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ var _ = Describe("SimpleCache", func() {
Eventually(func() bool {
_, exists := cache.Get("key1")
return exists
}).WithTimeout(6 * time.Millisecond).WithPolling(time.Millisecond).Should(BeFalse())
}).WithTimeout(100 * time.Millisecond).WithPolling(time.Millisecond).Should(BeFalse())
})

It("handles concurrent access", func() {
Expand Down
Loading