From 8d7b1b67e1aaf9f3ecbe0f8de7585051f206fd19 Mon Sep 17 00:00:00 2001 From: Nikhil Sinha Date: Wed, 27 Mar 2024 12:57:19 +0530 Subject: [PATCH] updated test cases for ingestion with time partition --- quest_test.go | 24 ++++++++++++++++++++++ scripts/load_historical_batch_events.js | 8 ++------ test_utils.go | 27 +++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/quest_test.go b/quest_test.go index e2d21b4..64ac600 100644 --- a/quest_test.go +++ b/quest_test.go @@ -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" diff --git a/scripts/load_historical_batch_events.js b/scripts/load_historical_batch_events.js index ce42588..9819f63 100644 --- a/scripts/load_historical_batch_events.js +++ b/scripts/load_historical_batch_events.js @@ -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() { diff --git a/test_utils.go b/test_utils.go index d8b0f92..58802d5 100644 --- a/test_utils.go +++ b/test_utils.go @@ -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)