Skip to content

Commit

Permalink
fix: fixed search-logs-test in the internal testsuite (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
leoporoli committed Jan 6, 2023
1 parent 89bf3e7 commit 3196e6c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
Expand Up @@ -22,15 +22,17 @@ const (

exampleServiceIdPrefix = "search-logs-"

shouldFollowLogs = true
shouldNotFollowLogs = false

service1ServiceID services.ServiceID = exampleServiceIdPrefix + "service-1"

firstFilterText = "Starting feature"
secondFilterText = "network"
firstFilterText = "The data have being loaded"
secondFilterText = "Starting feature"
thirdFilterText = "network"
matchRegexFilterStr = "Starting.*logs'"

testTimeOut = 90 * time.Second
testTimeOut = 180 * time.Second

logLine1 = "Starting feature 'centralized logs'"
logLine2 = "Starting feature 'network partitioning'"
Expand All @@ -52,19 +54,24 @@ var (
service1ServiceID: service1LogLines,
}

doesContainTextFilter = kurtosis_context.NewDoesContainTextLogLineFilter(firstFilterText)
doesNotContainTextFilter = kurtosis_context.NewDoesNotContainTextLogLineFilter(secondFilterText)
doesContainMatchRegexFilter = kurtosis_context.NewDoesContainMatchRegexLogLineFilter(matchRegexFilterStr)
doesNotContainMatchRegexFilter = kurtosis_context.NewDoesNotContainMatchRegexLogLineFilter(matchRegexFilterStr)
doesContainTextFilterForFirstRequest = kurtosis_context.NewDoesContainTextLogLineFilter(firstFilterText)
doesContainTextFilterForSecondRequest = kurtosis_context.NewDoesContainTextLogLineFilter(secondFilterText)
doesNotContainTextFilter = kurtosis_context.NewDoesNotContainTextLogLineFilter(thirdFilterText)
doesContainMatchRegexFilter = kurtosis_context.NewDoesContainMatchRegexLogLineFilter(matchRegexFilterStr)
doesNotContainMatchRegexFilter = kurtosis_context.NewDoesNotContainMatchRegexLogLineFilter(matchRegexFilterStr)

filtersByRequest = []kurtosis_context.LogLineFilter{
*doesContainTextFilter,
*doesContainTextFilterForFirstRequest,
*doesContainTextFilterForSecondRequest,
*doesNotContainTextFilter,
*doesContainMatchRegexFilter,
*doesNotContainMatchRegexFilter,
}

expectedLogLinesByRequest = [][]string{
{
logLine4,
},
{
logLine1,
logLine2,
Expand All @@ -83,6 +90,14 @@ var (
logLine4,
},
}

shouldFollowLogsValueByRequest = []bool{
shouldFollowLogs,
shouldNotFollowLogs,
shouldNotFollowLogs,
shouldNotFollowLogs,
shouldNotFollowLogs,
}
)

func TestSearchLogs(t *testing.T) {
Expand Down Expand Up @@ -118,6 +133,8 @@ func TestSearchLogs(t *testing.T) {
expectedLogLinesByService[serviceGuid] = expectedLogLinesByRequest[requestIndex]
}

shouldFollowLogsOption := shouldFollowLogsValueByRequest[requestIndex]

testEvaluationErr, receivedLogLinesByService, receivedNotFoundServiceGuids := test_helpers.GetLogsResponse(
t,
ctx,
Expand All @@ -126,7 +143,7 @@ func TestSearchLogs(t *testing.T) {
enclaveId,
userServiceGuids,
expectedLogLinesByService,
shouldNotFollowLogs,
shouldFollowLogsOption,
&filter,
)

Expand Down
Expand Up @@ -22,7 +22,7 @@ const (

exampleServiceId services.ServiceID = "stream-logs"

testTimeOut = 90 * time.Second
testTimeOut = 180 * time.Second

shouldFollowLogs = true
shouldNotFollowLogs = false
Expand Down
Expand Up @@ -10,19 +10,21 @@ import {
} from "kurtosis-sdk";
import {err, ok, Result} from "neverthrow";
import log from "loglevel";
import {getLogsResponseAndEvaluateResponse, addServicesWithLogLines} from "../../test_helpers/test_helpers";
import {addServicesWithLogLines, delay, getLogsResponseAndEvaluateResponse} from "../../test_helpers/test_helpers";

const TEST_NAME = "search-logs";
const IS_PARTITIONING_ENABLED = false;

const EXAMPLE_SERVICE_ID_PREFIX = "search-logs-";

const SHOULD_FOLLOW_LOGS = true;
const SHOULD_NOT_FOLLOW_LOGS = false;

const SERVICE_1_SERVICE_ID = EXAMPLE_SERVICE_ID_PREFIX + "service-1";

const FIRST_FILTER_TEXT = "Starting feature";
const SECOND_FILTER_TEXT = "network";
const FIRST_FILTER_TEXT = "The data have being loaded";
const SECOND_FILTER_TEXT = "Starting feature";
const THIRD_FILTER_TEXT = "network";
const MATCH_REGEX_FILTER_STR = "Starting.*logs'";

const LOG_LINE_1 = new ServiceLog("Starting feature 'centralized logs'");
Expand All @@ -38,19 +40,24 @@ const LOG_LINES_BY_SERVICE = new Map<ServiceID, ServiceLog[]>([
[SERVICE_1_SERVICE_ID, SERVICE_1_LOG_LINES],
])

const DOES_CONTAIN_TEXT_FILTER = LogLineFilter.NewDoesContainTextLogLineFilter(FIRST_FILTER_TEXT);
const DOES_NOT_CONTAIN_TEXT_FILTER = LogLineFilter.NewDoesNotContainTextLogLineFilter(SECOND_FILTER_TEXT);
const DOES_CONTAIN_TEXT_FILTER_FOR_FIRST_REQUEST = LogLineFilter.NewDoesContainTextLogLineFilter(FIRST_FILTER_TEXT);
const DOES_CONTAIN_TEXT_FILTER_FOR_SECOND_REQUEST = LogLineFilter.NewDoesContainTextLogLineFilter(SECOND_FILTER_TEXT);
const DOES_NOT_CONTAIN_TEXT_FILTER = LogLineFilter.NewDoesNotContainTextLogLineFilter(THIRD_FILTER_TEXT);
const DOES_CONTAIN_MATCH_REGEX_FILTER = LogLineFilter.NewDoesContainMatchRegexLogLineFilter(MATCH_REGEX_FILTER_STR);
const DOES_NOT_CONTAIN_MATCH_REGEX_FILTER = LogLineFilter.NewDoesNotContainMatchRegexLogLineFilter(MATCH_REGEX_FILTER_STR);

const FILTERS_BY_REQUEST = new Array<LogLineFilter>(
DOES_CONTAIN_TEXT_FILTER,
DOES_CONTAIN_TEXT_FILTER_FOR_FIRST_REQUEST,
DOES_CONTAIN_TEXT_FILTER_FOR_SECOND_REQUEST,
DOES_NOT_CONTAIN_TEXT_FILTER,
DOES_CONTAIN_MATCH_REGEX_FILTER,
DOES_NOT_CONTAIN_MATCH_REGEX_FILTER,
)

const EXPECTED_LOG_LINES_BY_REQUEST = Array<ServiceLog[]>(
[
LOG_LINE_1,
],
[
LOG_LINE_1,
LOG_LINE_2,
Expand All @@ -70,6 +77,14 @@ const EXPECTED_LOG_LINES_BY_REQUEST = Array<ServiceLog[]>(
],
)

const SHOULD_FOLLOW_LOGS_VALUES_BY_REQUEST: boolean[] = [
SHOULD_FOLLOW_LOGS,
SHOULD_NOT_FOLLOW_LOGS,
SHOULD_NOT_FOLLOW_LOGS,
SHOULD_NOT_FOLLOW_LOGS,
SHOULD_NOT_FOLLOW_LOGS,
]

jest.setTimeout(180000);

test("Test Search Logs", TestSearchLogs);
Expand Down Expand Up @@ -122,13 +137,15 @@ async function TestSearchLogs() {
for (let i = 0; i < FILTERS_BY_REQUEST.length; i++) {
const filter: LogLineFilter = FILTERS_BY_REQUEST[i];
const expectedLogLines: ServiceLog[] = EXPECTED_LOG_LINES_BY_REQUEST[i];
const shouldFollowLogsOption: boolean = SHOULD_FOLLOW_LOGS_VALUES_BY_REQUEST[i];
const executionResult = await executeGetLogsRequestAndEvaluateResult(
kurtosisContext,
enclaveId,
serviceGuid,
userServiceGuids,
filter,
expectedLogLines,
shouldFollowLogsOption,
);

if (executionResult.isErr()) {
Expand All @@ -152,6 +169,7 @@ async function executeGetLogsRequestAndEvaluateResult(
userServiceGuids: Set<ServiceGUID>,
logLineFilter: LogLineFilter,
expectedLogLines: ServiceLog[],
shouldFollowLogs: boolean,
): Promise<Result<null, Error>> {

const serviceGuids: Set<ServiceGUID> = new Set<ServiceGUID>([
Expand All @@ -168,7 +186,7 @@ async function executeGetLogsRequestAndEvaluateResult(
serviceGuids,
expectedLogLinesByService,
EXPECTED_NON_EXISTENCE_SERVICE_GUIDS,
SHOULD_NOT_FOLLOW_LOGS,
shouldFollowLogs,
logLineFilter,
)

Expand Down

0 comments on commit 3196e6c

Please sign in to comment.