MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestShutdownBuckets

Function TestShutdownBuckets

pkg/leakybucket/manager_run_test.go:109–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

107}
108
109func TestShutdownBuckets(t *testing.T) {
110 var (
111 bucketStore = NewBucketStore()
112 Holders = []BucketFactory{
113 // one long counter
114 {
115 Spec: BucketSpec{
116 Name: "test_counter_slow",
117 Description: "test_counter_slow",
118 Debug: true,
119 Type: "counter",
120 Capacity: -1,
121 Duration: "10m",
122 Filter: "true",
123 },
124 },
125 // slow leaky
126 {
127 Spec: BucketSpec{
128 Name: "test_leaky_slow",
129 Description: "test_leaky_slow",
130 Debug: true,
131 Type: "leaky",
132 Capacity: 5,
133 LeakSpeed: "10m",
134 Filter: "true",
135 },
136 },
137 }
138 )
139
140 for idx := range Holders {
141 if err := Holders[idx].LoadBucket(); err != nil {
142 t.Fatalf("while loading (%d/%d): %s", idx, len(Holders), err)
143 }
144
145 if err := Holders[idx].Validate(); err != nil {
146 t.Fatalf("while validating (%d/%d): %s", idx, len(Holders), err)
147 }
148 }
149
150 log.Info("Pouring to bucket")
151
152 in := pipeline.Event{Parsed: map[string]string{"something": "something"}}
153 // pour an item that will go to leaky + counter
154 ctx, cancel := context.WithCancel(t.Context())
155 ok, err := PourItemToHolders(ctx, in, Holders, bucketStore, nil)
156 if err != nil {
157 t.Fatalf("while pouring item : %s", err)
158 }
159
160 if !ok {
161 t.Fatal("didn't pour item")
162 }
163
164 time.Sleep(1 * time.Second)
165
166 if err := expectBucketCount(bucketStore, 2); err != nil {

Callers

nothing calls this directly

Calls 6

NewBucketStoreFunction · 0.85
PourItemToHoldersFunction · 0.85
expectBucketCountFunction · 0.85
LoadBucketMethod · 0.80
ValidateMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…