Skip to content

Commit

Permalink
Added test for large responses
Browse files Browse the repository at this point in the history
  • Loading branch information
loentar committed Jul 31, 2018
1 parent 0623ba3 commit be8aa4f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Expand Up @@ -32,9 +32,11 @@ if (HAS_WALL)
endif()

check_library_exists(dl dlopen "" HAS_DL)
check_include_file_cxx(sys/epoll.h HAS_EPOLL)
if (HAS_EPOLL)
add_definitions(-DHAS_EPOLL)
if (NOT APPLE)
check_include_file_cxx(sys/epoll.h HAS_EPOLL)
if (HAS_EPOLL)
add_definitions(-DHAS_EPOLL)
endif()
endif()

if (MINGW)
Expand Down
4 changes: 2 additions & 2 deletions core/utils/src/MemPool.cpp
Expand Up @@ -154,7 +154,7 @@ void MemPool::newChunk(uint64_t size)
{
if ((chunksCount + 1) > chunksReserved) { // we have ran out of chunks
const int newChunksReserved = chunksCount + NGREST_MEMPOOL_CHUNK_RESERVE;
Chunk* newChunks = reinterpret_cast<Chunk*>(realloc(chunks, sizeof(Chunk) * newChunksReserved));
Chunk* newChunks = reinterpret_cast<Chunk*>(realloc(chunks, sizeof(Chunk) * static_cast<size_t>(newChunksReserved)));
if (!newChunks)
throw std::bad_alloc();

Expand All @@ -164,7 +164,7 @@ void MemPool::newChunk(uint64_t size)
chunksReserved = newChunksReserved;
currChunk = chunks + chunksCount;
} else
++currChunk;
++currChunk;

++chunksCount;
++chunkIndex;
Expand Down
7 changes: 7 additions & 0 deletions tests/service/src/TestService.cpp
Expand Up @@ -60,6 +60,13 @@ void TestService::echoASync(const std::string& value, ngrest::Callback<const std
#endif
}

std::string TestService::largeResponse()
{
std::string res;
res.replace(0, 0, 65536, '_');
return res;
}

int TestService::add(int a, int b)
{
return a + b;
Expand Down
3 changes: 3 additions & 0 deletions tests/service/src/TestService.h
Expand Up @@ -88,6 +88,9 @@ class TestService: public ngrest::Service
// *resultElement: resultValue
std::string echoSync(const std::string& value);
void echoASync(const std::string& value, ngrest::Callback<const std::string&>& callback);

std::string largeResponse();

// default location is: add?a={a}&b={b}
int add(int a, int b);
void set(bool val);
Expand Down
5 changes: 5 additions & 0 deletions tests/service/test_client
Expand Up @@ -8,11 +8,16 @@ fi

baseurl=${1:-http://localhost:9098/ngrest/test/}

largeResponse="$(printf '_%.0s' {1..65536})"

# [method ]path[ request body]|expected response
tests=(
'get|{"result":true}'
'echoSync?value=test|{"resultValue":"You said test"}'
'echoASync?value=test|{"result":"You said test"}'

'largeResponse|{"result":"'"$largeResponse"'"}'

'add?a=1&b=2|{"result":3}'
'set?val=true|'
'notify|'
Expand Down

0 comments on commit be8aa4f

Please sign in to comment.