Skip to content

Commit

Permalink
add case
Browse files Browse the repository at this point in the history
Signed-off-by: stdpain <[email protected]>
  • Loading branch information
stdpain committed Dec 24, 2024
1 parent cc8f32d commit 54a4fac
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions be/test/exec/pipeline/schedule/observer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <bits/types/struct_timespec.h>
#include <unistd.h>

#include <atomic>
#include <condition_variable>
Expand Down Expand Up @@ -120,6 +121,31 @@ TEST(TimerThreadTest, test) {
noop.unschedule(&timer);
ASSERT_FALSE(changed);
}
{
std::counting_semaphore<> s(0);
int changed = false;
struct SleepTimer : public PipelineTimerTask {
SleepTimer(int32_t& changed_, std::counting_semaphore<>& s_) : changed(changed_), s(s_) {}
void Run() override {
s.release();
(void)sleep(5);
changed = true;
}
int32_t& changed;
std::counting_semaphore<>& s;
};
SleepTimer noop(changed, s);
//
timespec abstime = butil::microseconds_to_timespec(butil::gettimeofday_us());
timespec s1 = abstime;
s1.tv_sec -= 10;
// schedule a expired task
ASSERT_OK(timer.schedule(&noop, s1));
s.acquire();
// will wait util timer finished
noop.unschedule(&timer);
ASSERT_TRUE(changed);
}
}

TEST(ObservableTest, test) {
Expand Down

0 comments on commit 54a4fac

Please sign in to comment.