mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
inlet/kafka: also fix test for random load balancing
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Nix dependency hashes / Update dependency hashes (push) Has been cancelled
We expect a few messages in each partition.
This commit is contained in:
@@ -159,14 +159,15 @@ func TestLoadBalancingAlgorithm(t *testing.T) {
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
expected := make(map[int32]int, len(messages))
|
||||
expected := make(map[int32]int, DefaultMockKafkaNumPartitions)
|
||||
switch algo {
|
||||
case LoadBalanceRandom:
|
||||
for p, count := range messages {
|
||||
if count > total/len(messages)*2/10 && count < total/len(messages)*18/10 {
|
||||
expected[p] = count
|
||||
for p := range DefaultMockKafkaNumPartitions {
|
||||
p := int32(p)
|
||||
if messages[p] > total/DefaultMockKafkaNumPartitions*2/10 {
|
||||
expected[p] = messages[p]
|
||||
} else {
|
||||
expected[p] = total / len(messages)
|
||||
expected[p] = total / DefaultMockKafkaNumPartitions
|
||||
}
|
||||
}
|
||||
case LoadBalanceByExporter:
|
||||
|
||||
@@ -16,6 +16,9 @@ import (
|
||||
"akvorado/common/reporter"
|
||||
)
|
||||
|
||||
// DefaultMockKafkaNumPartitions is the default number of partitions for the mock Kafka.
|
||||
const DefaultMockKafkaNumPartitions = 8
|
||||
|
||||
// NewMock creates a new Kafka component with a mocked Kafka. It will
|
||||
// panic if it cannot be started.
|
||||
func NewMock(t *testing.T, r *reporter.Reporter, configuration Configuration) (*Component, *kfake.Cluster) {
|
||||
@@ -24,6 +27,7 @@ func NewMock(t *testing.T, r *reporter.Reporter, configuration Configuration) (*
|
||||
cluster, err := kfake.NewCluster(
|
||||
kfake.NumBrokers(1),
|
||||
kfake.AllowAutoTopicCreation(),
|
||||
kfake.DefaultNumPartitions(DefaultMockKafkaNumPartitions),
|
||||
kfake.WithLogger(kafka.NewLogger(r)),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user