Skip to content

Commit

Permalink
more logical tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkrishnads committed Aug 19, 2024
1 parent a9dc47b commit 8328baa
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 7 deletions.
38 changes: 31 additions & 7 deletions quest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,22 @@ func TestActivateHotTier(t *testing.T) {
DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
}

// create stream, put hot tier, ingest data for a duration, wait for 2-3 mins to see if all data is available in hot tier
func TestHotTierGetsLogs(t *testing.T) {
// create stream, put hot tier, ingest data for a duration, wait for 2-3 mins to see if all data is available in hot tier
if NewGlob.IngestorUrl.String() == "" {
t.Skip("Skipping in standalone mode")
}

// DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
createAndIngest(t)
activateHotTier(t)
time.Sleep(2 * 60 * time.Second) // wait 2 minutes for hot tier to sync

htCount := QueryLogStreamCount(t, NewGlob.QueryClient, NewGlob.Stream, 200)
disableHotTier(t)
DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)

require.Equalf(t, htCount, `[{"count":200}]`, "Ingested 200 logs, but hot tier contains %s", htCount)
}

// create stream, ingest data for a duration, set hot tier, wait for 2-3 mins to see if all data is available in hot tier
Expand Down Expand Up @@ -453,15 +464,28 @@ func TestHotTierLogCount(t *testing.T) {
time.Sleep(60 * 2 * time.Second) // wait for 2 minutes to allow hot tier to sync

countAfter := QueryLogStreamCount(t, NewGlob.QueryClient, NewGlob.Stream, 200)

DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
require.Equalf(t, countBefore, countAfter, "Ingested %s, but hot tier contains only %s", countBefore, countAfter)
}

func TestOldestHotTierEntry(t *testing.T) {
// create stream, ingest data for a duration, call GET /logstream/{logstream}/info - to get the first_event_at field then set hot tier, wait for 2-3 mins, call GET /hottier - to get oldest entry in hot tier then match both
if NewGlob.IngestorUrl.String() == "" {
t.Skip("Skipping in standalone mode")
}
}
// create stream, ingest data for a duration, call GET /logstream/{logstream}/info - to get the first_event_at field then set hot tier, wait for 2-3 mins, call GET /hottier - to get oldest entry in hot tier then match both
// func TestOldestHotTierEntry(t *testing.T) {
// if NewGlob.IngestorUrl.String() == "" {
// t.Skip("Skipping in standalone mode")
// }

// createAndIngest(t)
// streamInfo := getStreamInfo(t)

// activateHotTier(t)
// time.Sleep(60 * 2 * time.Second)

// hottier := getHotTierStatus(t)

// DeleteStream(t, NewGlob.QueryClient, NewGlob.Stream)
// require.Equalf(t, streamInfo.FirstEventAt, hottier.OldestDateTimeEntry, "The first event at in the stream info is %s but the oldest entry in hot tier is %s", *streamInfo.FirstEventAt, *hottier.OldestDateTimeEntry)
// }

// This test calls all the User API endpoints
// in a sequence to check if they work as expected.
Expand Down
52 changes: 52 additions & 0 deletions test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ type StreamHotTier struct {
OldestDateTimeEntry *string `json:"oldest_date_time_entry,omitempty"`
}

type StreamInfo struct {
CreatedAt string `json:"created-at"`
FirstEventAt *string `json:"first-event-at"`
CacheEnabled *bool `json:"cache_enabled"`
TimePartition *string `json:"time_partition"`
TimePartitionLimit *string `json:"time_partition_limit"`
CustomPartition *string `json:"custom_partition"`
StaticSchemaFlag *string `json:"static_schema_flag"`
}

func flogStreamFields() []string {
return []string{
"p_timestamp",
Expand Down Expand Up @@ -591,10 +601,52 @@ func activateHotTier(t *testing.T) {
}
}

func getHotTierStatus(t *testing.T) *StreamHotTier {
req, err := NewGlob.QueryClient.NewRequest("GET", "logstream/"+NewGlob.Stream+"/hottier", nil)
require.NoError(t, err, "Failed to create request")

req.Header.Set("Content-Type", "application/json")

response, err := NewGlob.QueryClient.Do(req)
require.NoError(t, err, "Failed to execute GET /hottier")
defer response.Body.Close()

body := readAsString(response.Body)

require.Equal(t, 200, response.StatusCode, "GET hot tier failed with status code: %d & body: %s", response.StatusCode, body)

var hotTierStatus StreamHotTier
err = json.Unmarshal([]byte(body), &hotTierStatus)
require.NoError(t, err, "The response from GET /hottier isn't of expected schema: %s", body)

return &hotTierStatus
}

func disableHotTier(t *testing.T) {
req, _ := NewGlob.QueryClient.NewRequest("DELETE", "logstream/"+NewGlob.Stream+"/hottier", nil)
response, err := NewGlob.QueryClient.Do(req)
body := readAsString(response.Body)
require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s and response: %s", response.Status, body)
require.NoErrorf(t, err, "Disabling hot tier failed: %s", err)
}

func getStreamInfo(t *testing.T) *StreamInfo {
req, err := NewGlob.QueryClient.NewRequest("GET", "logstream/"+NewGlob.Stream+"/info", nil)
require.NoError(t, err, "Failed to create request")

req.Header.Set("Content-Type", "application/json")

response, err := NewGlob.QueryClient.Do(req)
require.NoError(t, err, "Failed to execute GET /logstream/{stream_name}/info")
defer response.Body.Close()

body := readAsString(response.Body)

require.Equal(t, 200, response.StatusCode, "GET /logstream/{stream_name}/info failed with status code: %d & body: %s", response.StatusCode, body)

var streamInfo StreamInfo
err = json.Unmarshal([]byte(body), &streamInfo)
require.NoError(t, err, "The response from GET /info isn't of expected schema: %s", body)

return &streamInfo
}

0 comments on commit 8328baa

Please sign in to comment.