2022-05-03 07:03:41 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2022-09-06 09:09:34 +02:00
|
|
|
|
2023-03-02 13:19:45 +01:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/native"
|
2022-09-06 09:09:34 +02:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/stepper"
|
2022-05-03 07:03:41 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// If you want to run this test:
|
|
|
|
// 1. run two instances of victoriametrics and define -httpListenAddr for both or just for second instance
|
|
|
|
// 2. define srcAddr and dstAddr const with your victoriametrics addresses
|
|
|
|
// 3. define matchFilter const with your importing data
|
|
|
|
// 4. define timeStartFilter
|
|
|
|
// 5. run each test one by one
|
|
|
|
|
|
|
|
const (
|
|
|
|
matchFilter = `{job="avalanche"}`
|
|
|
|
timeStartFilter = "2020-01-01T20:07:00Z"
|
2022-09-06 09:09:34 +02:00
|
|
|
timeEndFilter = "2020-08-01T20:07:00Z"
|
2022-05-03 07:03:41 +02:00
|
|
|
srcAddr = "http://127.0.0.1:8428"
|
|
|
|
dstAddr = "http://127.0.0.1:8528"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This test simulates close process if user abort it
|
|
|
|
func Test_vmNativeProcessor_run(t *testing.T) {
|
|
|
|
t.Skip()
|
|
|
|
type fields struct {
|
2023-03-02 13:19:45 +01:00
|
|
|
filter native.Filter
|
2022-05-03 07:03:41 +02:00
|
|
|
rateLimit int64
|
2023-03-02 13:19:45 +01:00
|
|
|
dst *native.Client
|
|
|
|
src *native.Client
|
2022-05-03 07:03:41 +02:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
closer func(cancelFunc context.CancelFunc)
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "simulate syscall.SIGINT",
|
|
|
|
fields: fields{
|
2023-03-02 13:19:45 +01:00
|
|
|
filter: native.Filter{
|
|
|
|
Match: matchFilter,
|
|
|
|
TimeStart: timeStartFilter,
|
2022-05-03 07:03:41 +02:00
|
|
|
},
|
|
|
|
rateLimit: 0,
|
2023-03-02 13:19:45 +01:00
|
|
|
dst: &native.Client{
|
|
|
|
Addr: dstAddr,
|
2022-05-03 07:03:41 +02:00
|
|
|
},
|
2023-03-02 13:19:45 +01:00
|
|
|
src: &native.Client{
|
|
|
|
Addr: srcAddr,
|
2022-05-03 07:03:41 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
closer: func(cancelFunc context.CancelFunc) {
|
|
|
|
time.Sleep(time.Second * 5)
|
|
|
|
cancelFunc()
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simulate correct work",
|
|
|
|
fields: fields{
|
2023-03-02 13:19:45 +01:00
|
|
|
filter: native.Filter{
|
|
|
|
Match: matchFilter,
|
|
|
|
TimeStart: timeStartFilter,
|
2022-05-03 07:03:41 +02:00
|
|
|
},
|
|
|
|
rateLimit: 0,
|
2023-03-02 13:19:45 +01:00
|
|
|
dst: &native.Client{
|
|
|
|
Addr: dstAddr,
|
2022-05-03 07:03:41 +02:00
|
|
|
},
|
2023-03-02 13:19:45 +01:00
|
|
|
src: &native.Client{
|
|
|
|
Addr: srcAddr,
|
2022-05-03 07:03:41 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
closer: func(cancelFunc context.CancelFunc) {},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2022-09-06 09:09:34 +02:00
|
|
|
{
|
|
|
|
name: "simulate correct work with chunking",
|
|
|
|
fields: fields{
|
2023-03-02 13:19:45 +01:00
|
|
|
filter: native.Filter{
|
|
|
|
Match: matchFilter,
|
|
|
|
TimeStart: timeStartFilter,
|
|
|
|
TimeEnd: timeEndFilter,
|
|
|
|
Chunk: stepper.StepMonth,
|
2022-09-06 09:09:34 +02:00
|
|
|
},
|
|
|
|
rateLimit: 0,
|
2023-03-02 13:19:45 +01:00
|
|
|
dst: &native.Client{
|
|
|
|
Addr: dstAddr,
|
2022-09-06 09:09:34 +02:00
|
|
|
},
|
2023-03-02 13:19:45 +01:00
|
|
|
src: &native.Client{
|
|
|
|
Addr: srcAddr,
|
2022-09-06 09:09:34 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
closer: func(cancelFunc context.CancelFunc) {},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
2022-05-03 07:03:41 +02:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
ctx, cancelFn := context.WithCancel(context.Background())
|
|
|
|
p := &vmNativeProcessor{
|
|
|
|
filter: tt.fields.filter,
|
|
|
|
rateLimit: tt.fields.rateLimit,
|
|
|
|
dst: tt.fields.dst,
|
|
|
|
src: tt.fields.src,
|
|
|
|
}
|
|
|
|
|
|
|
|
tt.closer(cancelFn)
|
|
|
|
|
2023-03-02 13:19:45 +01:00
|
|
|
if err := p.run(ctx, true); (err != nil) != tt.wantErr {
|
2022-05-03 07:03:41 +02:00
|
|
|
t.Errorf("run() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|