1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/test/adapter/test_timer.cc
Falk Werner 07e32757f8
chore(webfuse) Increase test coverage (#34)
* removes unnecessary code

* adds test of wf_status

* adds tests of wf_message

* adds tests of wf_message_queue

* changed branch of coverage badge to display correct results

* moves core tests into separate subdirectory

* increases coverage of timer test

* moves adapter specific tests into separate directory

* moves provider specific tests into separate directory

* adds tests of jsonrpc utilities

* adds tests of jsonrpc request

* adds test of jsonrpc response

* adds tests of jsonrpc server

* adds tests of jsonrpc proxy

* adds integration test (found some issues)

* disables problematic tests

* fixes resource leak: pending timer after cleanup proxy

* fixes order of cleanup to prevent processing pending requests after filesystem shut down

* fixes some memcheck and helgrind errors: initialization of lws_log; setup of client and server

* disabled a test

* fixes error in msleep utility

* fixes deadlock at IntegrationTest using valgrind

* removes unit test code from coverage report

* adds some integration tests

* makes badge show coverage of master

* fixes some coding style issues

* fixes eary trigger of is_connected (provider)

* fixes read error in 32 bit environments\n\ninode is always 64 bit, but variadic wf_impl_jsonrpc_proxy_invoke expects int
2019-05-19 14:33:42 +02:00

150 lines
3.6 KiB
C++

#include <gtest/gtest.h>
#include <cstddef>
#include "msleep.hpp"
#include "webfuse/adapter/impl/time/timer.h"
#include "webfuse/adapter/impl/time/timeout_manager.h"
using std::size_t;
using webfuse_test::msleep;
namespace
{
void on_timeout(struct wf_impl_timer * timer)
{
bool * triggered = reinterpret_cast<bool*>(timer->user_data);
*triggered = true;
}
}
TEST(timer, init)
{
struct wf_impl_timeout_manager manager;
struct wf_impl_timer timer;
wf_impl_timeout_manager_init(&manager);
wf_impl_timer_init(&timer, &manager);
wf_impl_timer_cleanup(&timer);
wf_impl_timeout_manager_cleanup(&manager);
}
TEST(timer, trigger)
{
struct wf_impl_timeout_manager manager;
struct wf_impl_timer timer;
wf_impl_timeout_manager_init(&manager);
wf_impl_timer_init(&timer, &manager);
bool triggered = false;
wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
msleep(500);
wf_impl_timeout_manager_check(&manager);
ASSERT_TRUE(triggered);
wf_impl_timer_cleanup(&timer);
wf_impl_timeout_manager_cleanup(&manager);
}
TEST(timer, trigger_on_cleanup)
{
struct wf_impl_timeout_manager manager;
struct wf_impl_timer timer;
wf_impl_timeout_manager_init(&manager);
wf_impl_timer_init(&timer, &manager);
bool triggered = false;
wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(5 * 60 * 1000), &on_timeout, reinterpret_cast<void*>(&triggered));
wf_impl_timeout_manager_cleanup(&manager);
ASSERT_TRUE(triggered);
wf_impl_timer_cleanup(&timer);
}
TEST(timer, cancel)
{
struct wf_impl_timeout_manager manager;
struct wf_impl_timer timer;
wf_impl_timeout_manager_init(&manager);
wf_impl_timer_init(&timer, &manager);
bool triggered = false;
wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(250), &on_timeout, &triggered);
msleep(500);
wf_impl_timer_cancel(&timer);
wf_impl_timeout_manager_check(&manager);
ASSERT_FALSE(triggered);
wf_impl_timer_cleanup(&timer);
wf_impl_timeout_manager_cleanup(&manager);
}
TEST(timer, cancel_multiple_timers)
{
static size_t const count = 5;
struct wf_impl_timeout_manager manager;
struct wf_impl_timer timer[count];
wf_impl_timeout_manager_init(&manager);
bool triggered = false;
for(size_t i = 0; i < count; i++)
{
wf_impl_timer_init(&timer[i], &manager);
wf_impl_timer_start(&timer[i], wf_impl_timepoint_in_msec(0), &on_timeout, &triggered);
}
msleep(10);
for(size_t i = 0; i < count; i++)
{
wf_impl_timer_cancel(&timer[i]);
}
wf_impl_timeout_manager_check(&manager);
ASSERT_FALSE(triggered);
for(size_t i = 0; i < count; i++)
{
wf_impl_timer_cleanup(&timer[0]);
}
wf_impl_timeout_manager_cleanup(&manager);
}
TEST(timer, multiple_timers)
{
static size_t const count = 5;
struct wf_impl_timeout_manager manager;
struct wf_impl_timer timer[count];
bool triggered[count];
wf_impl_timeout_manager_init(&manager);
for(size_t i = 0; i < count; i++)
{
wf_impl_timer_init(&timer[i], &manager);
triggered[i] = false;
wf_impl_timer_start(&timer[i], wf_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
}
for(size_t i = 0; i < count; i++)
{
msleep(100);
wf_impl_timeout_manager_check(&manager);
}
for(size_t i = 0; i < count; i++)
{
ASSERT_TRUE(triggered[i]);
wf_impl_timer_cleanup(&timer[i]);
}
wf_impl_timeout_manager_cleanup(&manager);
}