Skip to content

Commit

Permalink
updated test cases for ingestion with time partition
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsinhaparseable committed Mar 27, 2024
1 parent 7d112eb commit 8d7b1b6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
24 changes: 24 additions & 0 deletions quest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ func TestSmokeIngestEventsToStream(t *testing.T) {
DeleteStream(t, NewGlob.Client, NewGlob.Stream)
}

func TestTimePartition_TimeStampMismatch(t *testing.T) {
historicalStream := NewGlob.Stream + "historical"
timeHeader := map[string]string{"X-P-Time-Partition": "source_time"}
CreateStreamWithHeader(t, NewGlob.Client, historicalStream, timeHeader)
IngestOneEventWithTimePartition_TimeStampMismatch(t, historicalStream)
DeleteStream(t, NewGlob.Client, historicalStream)
}

func TestTimePartition_NoTimePartitionInLog(t *testing.T) {
historicalStream := NewGlob.Stream + "historical"
timeHeader := map[string]string{"X-P-Time-Partition": "source_time"}
CreateStreamWithHeader(t, NewGlob.Client, historicalStream, timeHeader)
IngestOneEventWithTimePartition_NoTimePartitionInLog(t, historicalStream)
DeleteStream(t, NewGlob.Client, historicalStream)
}

func TestTimePartition_IncorrectDateTimeFormatTimePartitionInLog(t *testing.T) {
historicalStream := NewGlob.Stream + "historical"
timeHeader := map[string]string{"X-P-Time-Partition": "source_time"}
CreateStreamWithHeader(t, NewGlob.Client, historicalStream, timeHeader)
IngestOneEventWithTimePartition_IncorrectDateTimeFormatTimePartitionInLog(t, historicalStream)
DeleteStream(t, NewGlob.Client, historicalStream)
}

func TestSmokeQueryTwoStreams(t *testing.T) {
stream1 := NewGlob.Stream + "1"
stream2 := NewGlob.Stream + "2"
Expand Down
8 changes: 2 additions & 6 deletions scripts/load_historical_batch_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ export const options = {
};

function current_time() {
const startDate = new Date('2022-01-01');
const endDate = new Date('2022-01-31');
const timeDiff = endDate.getTime() - startDate.getTime();
const randomTime = Math.random() * timeDiff;
const randomDate = new Date(startDate.getTime() + randomTime);
return(randomDate.toISOString());
let event = new Date();
return event.toUTCString();
}

function schemas() {
Expand Down
27 changes: 27 additions & 0 deletions test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ func RunFlog(t *testing.T, stream string) {
}
}

func IngestOneEventWithTimePartition_TimeStampMismatch(t *testing.T, stream string) {
var test_payload string = `{"source_time":"2024-03-26T18:08:00.434Z","level":"info","message":"Application is failing","version":"1.2.0","user_id":13912,"device_id":4138,"session_id":"abc","os":"Windows","host":"112.168.1.110","location":"ngeuprqhynuvpxgp","request_body":"rnkmffyawtdcindtrdqruyxbndbjpfsptzpwtujbmkwcqastmxwbvjwphmyvpnhordwljnodxhtvpjesjldtifswqbpyuhlcytmm","status_code":300,"app_meta":"ckgpibhmlusqqfunnpxbfxbc", "new_field_added_by":"ingester 8020"}`
req, _ := NewGlob.Client.NewRequest("POST", "ingest", bytes.NewBufferString(test_payload))
req.Header.Add("X-P-Stream", stream)
response, err := NewGlob.Client.Do(req)
require.NoErrorf(t, err, "Request failed: %s", err)
require.Equalf(t, 400, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body))
}

func IngestOneEventWithTimePartition_NoTimePartitionInLog(t *testing.T, stream string) {
var test_payload string = `{"level":"info","message":"Application is failing","version":"1.2.0","user_id":13912,"device_id":4138,"session_id":"abc","os":"Windows","host":"112.168.1.110","location":"ngeuprqhynuvpxgp","request_body":"rnkmffyawtdcindtrdqruyxbndbjpfsptzpwtujbmkwcqastmxwbvjwphmyvpnhordwljnodxhtvpjesjldtifswqbpyuhlcytmm","status_code":300,"app_meta":"ckgpibhmlusqqfunnpxbfxbc", "new_field_added_by":"ingester 8020"}`
req, _ := NewGlob.Client.NewRequest("POST", "ingest", bytes.NewBufferString(test_payload))
req.Header.Add("X-P-Stream", stream)
response, err := NewGlob.Client.Do(req)
require.NoErrorf(t, err, "Request failed: %s", err)
require.Equalf(t, 400, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body))
}

func IngestOneEventWithTimePartition_IncorrectDateTimeFormatTimePartitionInLog(t *testing.T, stream string) {
var test_payload string = `{"source_time":"2024-03-26", "level":"info","message":"Application is failing","version":"1.2.0","user_id":13912,"device_id":4138,"session_id":"abc","os":"Windows","host":"112.168.1.110","location":"ngeuprqhynuvpxgp","request_body":"rnkmffyawtdcindtrdqruyxbndbjpfsptzpwtujbmkwcqastmxwbvjwphmyvpnhordwljnodxhtvpjesjldtifswqbpyuhlcytmm","status_code":300,"app_meta":"ckgpibhmlusqqfunnpxbfxbc", "new_field_added_by":"ingester 8020"}`
req, _ := NewGlob.Client.NewRequest("POST", "ingest", bytes.NewBufferString(test_payload))
req.Header.Add("X-P-Stream", stream)
response, err := NewGlob.Client.Do(req)
require.NoErrorf(t, err, "Request failed: %s", err)
require.Equalf(t, 400, response.StatusCode, "Server returned http code: %s resp %s", response.Status, readAsString(response.Body))
}

func QueryLogStreamCount(t *testing.T, client HTTPClient, stream string, count uint64) {
// Query last 10 minutes of data only
endTime := time.Now().Add(time.Second).Format(time.RFC3339Nano)
Expand Down

0 comments on commit 8d7b1b6

Please sign in to comment.