app/vmctl: fix tests (#4345)

This commit is contained in:
Dmytro Kozlov 2023-05-25 18:04:04 +03:00 committed by GitHub
parent 66ed6fe62f
commit 4060f3f261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ package remote_read_integration
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"log"
@ -10,6 +11,7 @@ import (
"reflect"
"sort"
"strconv"
"sync"
"testing"
"time"
@ -169,14 +171,21 @@ func (rws *RemoteWriteServer) valuesHandler() http.Handler {
Data: metricNames,
}
err := json.NewEncoder(w).Encode(resp)
buf := bytes.NewBuffer(nil)
err := json.NewEncoder(buf).Encode(resp)
if err != nil {
log.Printf("error send series: %s", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
w.WriteHeader(http.StatusOK)
_, err = w.Write(buf.Bytes())
if err != nil {
log.Printf("error send series: %s", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
return
})
}
@ -191,7 +200,6 @@ func (rws *RemoteWriteServer) exportNativeHandler() http.Handler {
return
}
w.WriteHeader(http.StatusNoContent)
return
})
}
@ -202,6 +210,7 @@ func (rws *RemoteWriteServer) importNativeHandler(t *testing.T) http.Handler {
defer common.StopUnmarshalWorkers()
var gotTimeSeries []vm.TimeSeries
var mx sync.RWMutex
err := stream.Parse(r.Body, false, func(block *stream.Block) error {
mn := &block.MetricName
@ -218,7 +227,9 @@ func (rws *RemoteWriteServer) importNativeHandler(t *testing.T) http.Handler {
})
}
mx.Lock()
gotTimeSeries = append(gotTimeSeries, timeseries)
mx.Unlock()
return nil
})
@ -244,7 +255,8 @@ func (rws *RemoteWriteServer) importNativeHandler(t *testing.T) http.Handler {
if !reflect.DeepEqual(gotTimeSeries, rws.expectedSeries) {
w.WriteHeader(http.StatusInternalServerError)
t.Fatalf("datasets not equal, expected: %#v;\n got: %#v", rws.expectedSeries, gotTimeSeries)
t.Errorf("datasets not equal, expected: %#v;\n got: %#v", rws.expectedSeries, gotTimeSeries)
return
}
w.WriteHeader(http.StatusNoContent)