-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtransaction.cpp
69 lines (53 loc) · 1.49 KB
/
transaction.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Copyright (C) 2020-2023 Krylov Yaroslav.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include "ureact/transaction.hpp"
#include "catch2_extra.hpp"
#include "ureact/adaptor/count.hpp"
#include "ureact/adaptor/lift.hpp"
#include "ureact/adaptor/monitor.hpp"
TEST_CASE( "ureact::transaction" )
{
ureact::context ctx;
ureact::var_signal src = ureact::make_var( ctx, 1 );
auto change_count = ureact::count( ureact::monitor( src ) );
{
ureact::transaction _{ ctx };
src <<= 6;
src <<= 7;
src <<= -1;
}
CHECK( change_count.get() == 1 );
}
// A transaction can be started inside an active transaction
// Only the first transaction takes effect
TEST_CASE( "Recursive transactions" )
{
ureact::context ctx;
ureact::var_signal src = ureact::make_var( ctx, 1 );
auto change_count = ureact::count( ureact::monitor( src ) );
{
ureact::transaction _{ ctx };
src <<= 7;
[&] {
ureact::transaction _{ ctx };
src <<= 4;
}();
src <<= 1;
src <<= 2;
}
CHECK( change_count.get() == 1 );
}
TEST_CASE( "Context death inside transaction" )
{
auto contextPtr = std::make_unique<ureact::context>();
{
ureact::transaction _( *contextPtr );
contextPtr.reset();
}
CHECK( true ); // test should not fail under asan
}