Fixed concurrent tests
git-svn-id: svn://db.shs.com.ru/pip@892 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
//
|
||||
// Created by fomenko on 23.09.2019.
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "piblockingdequeue.h"
|
||||
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//
|
||||
// Created by fomenko on 26.09.2019.
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
@@ -16,27 +12,27 @@ public:
|
||||
|
||||
TEST_F(ConditionLock, lock_is_protect) {
|
||||
m->lock();
|
||||
bool isProtect = true;
|
||||
bool* isProtect = new bool(true);
|
||||
|
||||
createThread([&](){
|
||||
m->lock();
|
||||
isProtect = false;
|
||||
*isProtect = false;
|
||||
});
|
||||
ASSERT_TRUE(isProtect);
|
||||
EXPECT_FALSE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
ASSERT_TRUE(*isProtect);
|
||||
}
|
||||
|
||||
TEST_F(ConditionLock, unlock_is_release) {
|
||||
m->lock();
|
||||
volatile bool isReleased = false;
|
||||
bool* isReleased = new bool(false);
|
||||
m->unlock();
|
||||
|
||||
createThread([&](){
|
||||
m->lock();
|
||||
isReleased = true;
|
||||
*isReleased = true;
|
||||
m->unlock();
|
||||
});
|
||||
EXPECT_TRUE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
ASSERT_TRUE(isReleased);
|
||||
ASSERT_TRUE(*isReleased);
|
||||
}
|
||||
|
||||
TEST_F(ConditionLock, tryLock_is_false_when_locked) {
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//
|
||||
// Created by fomenko on 24.09.2019.
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "piconditionvar.h"
|
||||
#include "pithread.h"
|
||||
@@ -14,10 +10,8 @@ public:
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
isRunning = false;
|
||||
variable = new PIConditionVariable();
|
||||
adapterFunctionDefault = [&](){
|
||||
isRunning = true;
|
||||
m.lock();
|
||||
variable->wait(m);
|
||||
m.unlock();
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
//
|
||||
// Created by fomenko on 24.09.2019.
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "executor.h"
|
||||
#include "pimutex.h"
|
||||
@@ -51,8 +47,8 @@ TEST(ExcutorIntegrationTest, execute_is_awaitTermination_wait) {
|
||||
});
|
||||
executorService.shutdown();
|
||||
PITimeMeasurer measurer;
|
||||
ASSERT_TRUE(executorService.awaitTermination(4 * WAIT_THREAD_TIME_MS));
|
||||
ASSERT_TRUE(executorService.awaitTermination(3 * WAIT_THREAD_TIME_MS));
|
||||
double waitTime = measurer.elapsed_m();
|
||||
ASSERT_GE(waitTime, WAIT_THREAD_TIME_MS);
|
||||
ASSERT_LE(waitTime, 3 * WAIT_THREAD_TIME_MS);
|
||||
ASSERT_LE(waitTime, 4 * WAIT_THREAD_TIME_MS);
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
//
|
||||
// Created by fomenko on 27.09.2019.
|
||||
//
|
||||
|
||||
#ifndef AWRCANFLASHER_TESTUTIL_H
|
||||
#define AWRCANFLASHER_TESTUTIL_H
|
||||
|
||||
@@ -20,13 +16,16 @@ PIOBJECT(TestUtil)
|
||||
public:
|
||||
double threadStartTime;
|
||||
PIThread* thread = new PIThread();
|
||||
volatile bool isRunning;
|
||||
volatile bool isRunning = false;
|
||||
std::function<void()> adapterFunctionDefault;
|
||||
|
||||
bool createThread(const std::function<void()>& fun = nullptr, PIThread* thread_ = nullptr) {
|
||||
std::function<void()> actualFun = fun == nullptr ? adapterFunctionDefault : fun;
|
||||
if (thread_ == nullptr) thread_ = thread;
|
||||
thread_->startOnce([=](void*){ actualFun(); });
|
||||
thread_->startOnce([=](void*){
|
||||
isRunning = true;
|
||||
actualFun();
|
||||
});
|
||||
return waitThread(thread_);
|
||||
}
|
||||
|
||||
@@ -36,7 +35,7 @@ public:
|
||||
while (!isRunning) {
|
||||
isTimeout = WAIT_THREAD_TIME_MS <= measurer.elapsed_m();
|
||||
if (isTimeout) break;
|
||||
piMSleep(1);
|
||||
piUSleep(100);
|
||||
}
|
||||
|
||||
threadStartTime = measurer.elapsed_m();
|
||||
|
||||
Reference in New Issue
Block a user