summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/query/query-old-large.cpp
blob: 8bdc65c12c18633ebfb68dcb160b575493474140 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/searchlib/query/query.h>
#include <vespa/searchlib/query/tree/querybuilder.h>
#include <vespa/searchlib/query/tree/simplequery.h>
#include <vespa/searchlib/query/tree/stackdumpcreator.h>
#include <vespa/vespalib/testkit/test_kit.h>
#include <limits>

using namespace search;
using namespace search::query;

namespace {

void setMaxStackSize(rlim_t maxStackSize)
{
    struct rlimit limit;
    getrlimit(RLIMIT_STACK, &limit);
    limit.rlim_cur = maxStackSize;
    setrlimit(RLIMIT_STACK, &limit);
}

}


// NOTE: This test explicitly sets thread stack size and will fail due to
// a stack overflow if the stack usage increases.
TEST("testveryLongQueryResultingInBug6850778") {
    const uint32_t NUMITEMS=20000;
    setMaxStackSize(4 * 1024 * 1024);
    QueryBuilder<SimpleQueryNodeTypes> builder;
    for (uint32_t i=0; i <= NUMITEMS; i++) {
        builder.addAnd(2);
        builder.addStringTerm("a", "", 0, Weight(0));
        if (i < NUMITEMS) {
        } else {
            builder.addStringTerm("b", "", 0, Weight(0));
        }
    }
    Node::UP node = builder.build();
    vespalib::string stackDump = StackDumpCreator::create(*node);

    QueryNodeResultFactory factory;
    Query q(factory, stackDump);
    QueryTermList terms;
    QueryNodeRefList phrases;
    q.getLeafs(terms);
    ASSERT_EQUAL(NUMITEMS + 2, terms.size());
}

TEST_MAIN() { TEST_RUN_ALL(); }