FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/core/system/ChildProcessSubprocPollTests.cpp at main · ssh352/rstudio · GitHub
ssh352
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
system
/
ChildProcessSubprocPollTests.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
235 lines (196 loc) · 6.62 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
core
/
system
/
ChildProcessSubprocPollTests.cpp
Copy path
File metadata and controls
235 lines (196 loc) · 6.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* ChildProcessSubprocPollTests.cpp
*
* Copyright (C) 2022 by Posit Software, PBC
*
* Unless you have received this program directly from Posit Software pursuant
* to the terms of a commercial license agreement with Posit Software, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
"
ChildProcessSubprocPoll.hpp
"
#
include
<
boost/bind/bind.hpp
>
#
include
<
boost/thread/thread.hpp
>
#
include
<
tests/TestThat.hpp
>
using
namespace
boost
::placeholders
;
namespace
rstudio
{
namespace
core
{
namespace
system
{
namespace
tests
{
namespace
{
using
boost::posix_time::milliseconds;
const
milliseconds
kResetRecentDelay
= milliseconds(
100
);
const
milliseconds
kResetRecentDelayExpired
= milliseconds(
110
);
const
milliseconds
kCheckSubprocDelay
= milliseconds(
25
);
const
milliseconds
kCheckSubprocDelayExpired
= milliseconds(
35
);
const
milliseconds
kCheckCwdDelay
= milliseconds(
35
);
const
milliseconds
kCheckCwdDelayExpired
= milliseconds(
45
);
void
blockingwait
(milliseconds ms)
{
boost::this_thread::sleep
(ms);
}
class
NoSubProcPollingFixture
{
public:
NoSubProcPollingFixture
(PidType pid)
:
poller_
(pid,
kResetRecentDelay
,
kCheckSubprocDelay
,
kCheckCwdDelay
,
0
, std::vector<std::string>(),
0
)
{}
ChildProcessSubprocPoll poller_;
};
class
SubProcPollingFixture
{
public:
SubProcPollingFixture
(PidType pid)
:
poller_
(pid,
kResetRecentDelay
,
kCheckSubprocDelay
,
kCheckCwdDelay
,
boost::bind
(&SubProcPollingFixture::checkSubproc,
this
, _1),
std::vector<std::string>(),
0),
checkReturns_(
false
),
callerPid_(
0
),
checkCalled_(
false
)
{}
std::vector<SubprocInfo>
checkSubproc
(PidType pid)
{
callerPid_ = pid;
checkCalled_ =
true
;
std::vector<SubprocInfo> result;
if
(checkReturns_)
{
SubprocInfo info;
info.
exe
=
"
some_exe
"
;
info.
pid
=
123
;
result.
push_back
(info);
}
return
result;
}
void
clearFlags
()
{
callerPid_ =
0
;
checkCalled_ =
false
;
}
ChildProcessSubprocPoll poller_;
bool
checkReturns_;
PidType callerPid_;
bool
checkCalled_;
};
class
CwdPollingFixture
{
public:
CwdPollingFixture
(PidType pid)
:
poller_
(pid,
kResetRecentDelay
,
kCheckSubprocDelay
,
kCheckCwdDelay
,
0
, std::vector<std::string>(),
boost::bind
(&CwdPollingFixture::checkCwd,
this
, _1)),
callerPid_
(
0
),
checkCalled_
(
false
)
{}
core::FilePath
checkCwd
(PidType pid)
{
callerPid_ = pid;
checkCalled_ =
true
;
return
checkReturns_;
}
void
clearFlags
()
{
callerPid_ =
0
;
checkCalled_ =
false
;
}
ChildProcessSubprocPoll poller_;
core::FilePath checkReturns_;
PidType callerPid_;
bool
checkCalled_;
};
}
//
anonymous namespace
test_context
(
"
ChildProcess polling support class
"
)
{
test_that
(
"
initial state without subproc polling matches expectation
"
)
{
PidType pid =
12345
;
NoSubProcPollingFixture
test
(pid);
expect_true
(test.
poller_
.
hasRecentOutput
());
expect_true
(test.
poller_
.
hasNonIgnoredSubprocess
());
expect_false
(test.
poller_
.
hasIgnoredSubprocess
());
}
test_that
(
"
recent input state without subproc polling doesn't change immediately
"
)
{
PidType pid =
12345
;
NoSubProcPollingFixture
test
(pid);
expect_false
(test.
poller_
.
poll
(
true
));
expect_true
(test.
poller_
.
hasRecentOutput
());
expect_false
(test.
poller_
.
poll
(
false
));
expect_true
(test.
poller_
.
hasRecentOutput
());
//
timeout hasn't expired
}
test_that
(
"
recent input state without subproc polling does change after timeout
"
)
{
PidType pid =
12345
;
NoSubProcPollingFixture
test
(pid);
test.
poller_
.
poll
(
true
);
expect_true
(test.
poller_
.
hasRecentOutput
());
blockingwait
(
kResetRecentDelayExpired
);
test.
poller_
.
poll
(
false
);
expect_false
(test.
poller_
.
hasRecentOutput
());
//
now it flips to false
test.
poller_
.
poll
(
true
);
expect_true
(test.
poller_
.
hasRecentOutput
());
//
but right back to true
}
test_that
(
"
initial state for subproc polling matches expectations
"
)
{
PidType pid =
12345
;
SubProcPollingFixture
test
(pid);
expect_true
(test.
poller_
.
hasRecentOutput
());
expect_true
(test.
poller_
.
hasNonIgnoredSubprocess
());
expect_false
(test.
poller_
.
hasIgnoredSubprocess
());
}
test_that
(
"
childproc checked when recent output and timeout expires
"
)
{
PidType pid =
12345
;
SubProcPollingFixture
test
(pid);
test.
checkReturns_
=
false
;
test.
poller_
.
poll
(
true
);
expect_false
(test.
checkCalled_
);
//
polling timeout hasn't passed
blockingwait
(
kCheckSubprocDelayExpired
);
//
longer than the subproc timeout
expect_true
(test.
poller_
.
poll
(
false
));
//
not longer than the recent output timeout!
expect_true
(test.
checkCalled_
);
expect_true
(test.
poller_
.
hasNonIgnoredSubprocess
() == test.
checkReturns_
);
expect_true
(test.
poller_
.
hasRecentOutput
());
expect_true
(test.
callerPid_
== pid);
}
test_that
(
"
lack of recent output prevents childproc checking
"
)
{
PidType pid =
12345
;
SubProcPollingFixture
test
(pid);
test.
checkReturns_
=
false
;
test.
poller_
.
poll
(
false
);
expect_false
(test.
checkCalled_
);
blockingwait
(
kCheckSubprocDelayExpired
);
//
long enough for childproc polling
test.
poller_
.
poll
(
false
);
//
not longer than the output timeout
expect_true
(test.
checkCalled_
);
expect_true
(test.
poller_
.
hasNonIgnoredSubprocess
() == test.
checkReturns_
);
expect_true
(test.
poller_
.
hasRecentOutput
());
expect_true
(test.
callerPid_
== pid);
test.
clearFlags
();
test.
poller_
.
poll
(
false
);
//
no recent output
blockingwait
(
kResetRecentDelayExpired
);
test.
poller_
.
poll
(
false
);
expect_false
(test.
checkCalled_
);
//
because of no recent output
expect_false
(test.
poller_
.
hasRecentOutput
());
expect_true
(test.
poller_
.
hasNonIgnoredSubprocess
() == test.
checkReturns_
);
}
test_that
(
"
initial state for cwd polling matches expectations
"
)
{
PidType pid =
12345
;
CwdPollingFixture
test
(pid);
expect_true
(test.
poller_
.
hasRecentOutput
());
expect_true
(test.
poller_
.
getCwd
().
isEmpty
());
}
}
}
//
namespace tests
}
//
namespace system
}
//
namespace core
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL