19
19
#include " llvm/Support/Path.h"
20
20
#include " llvm/Support/TargetSelect.h"
21
21
#include " gtest/gtest.h"
22
- #include < mutex>
22
+
23
+ #include < chrono>
23
24
#include < condition_variable>
25
+ #include < mutex>
26
+ #include < thread>
24
27
25
28
using namespace SourceKit ;
26
29
using namespace llvm ;
@@ -177,7 +180,7 @@ class EditTest : public ::testing::Test {
177
180
DocUpdState->HasUpdate = false ;
178
181
}
179
182
180
- void doubleOpenWithDelay (useconds_t delay, bool close);
183
+ void doubleOpenWithDelay (std::chrono::microseconds delay, bool close);
181
184
182
185
private:
183
186
std::vector<const char *> makeArgs (const char *DocName,
@@ -229,7 +232,8 @@ TEST_F(EditTest, DiagsAfterEdit) {
229
232
EXPECT_EQ (SemaDiagStage, Consumer.DiagStage );
230
233
}
231
234
232
- void EditTest::doubleOpenWithDelay (useconds_t delay, bool closeDoc) {
235
+ void EditTest::doubleOpenWithDelay (std::chrono::microseconds delay,
236
+ bool closeDoc) {
233
237
const char *DocName = " /test.swift" ;
234
238
const char *Contents =
235
239
" func foo() { _ = unknown_name }\n " ;
@@ -239,8 +243,8 @@ void EditTest::doubleOpenWithDelay(useconds_t delay, bool closeDoc) {
239
243
open (DocName, Contents, Args, Consumer);
240
244
ASSERT_EQ (0u , Consumer.Diags .size ());
241
245
// Open again without closing; this reinitializes the semantic info on the doc
242
- if (delay)
243
- usleep (delay);
246
+ if (delay > std::chrono::microseconds ( 0 ) )
247
+ std::this_thread::sleep_for (delay);
244
248
if (closeDoc)
245
249
close (DocName);
246
250
reset (Consumer);
@@ -277,19 +281,19 @@ TEST_F(EditTest, DISABLED_DiagsAfterCloseAndReopen) {
277
281
// The middle case in particular verifies the ASTManager is only calling the
278
282
// correct ASTConsumers.
279
283
280
- doubleOpenWithDelay (0 , true );
281
- doubleOpenWithDelay (1000 , true ); // 1 ms
282
- doubleOpenWithDelay (10000 , true ); // 10 ms
283
- doubleOpenWithDelay (100000 , true ); // 100 ms
284
+ doubleOpenWithDelay (std::chrono::microseconds ( 0 ) , true );
285
+ doubleOpenWithDelay (std::chrono::milliseconds ( 1 ) , true );
286
+ doubleOpenWithDelay (std::chrono::milliseconds ( 10 ) , true );
287
+ doubleOpenWithDelay (std::chrono::milliseconds ( 100 ) , true );
284
288
}
285
289
286
290
TEST_F (EditTest, DiagsAfterReopen) {
287
291
// See description of DiagsAfterCloseAndReopen, but in this case we don't
288
292
// close the original document, causing it to reinitialize instead of create
289
293
// a fresh document.
290
294
291
- doubleOpenWithDelay (0 , false );
292
- doubleOpenWithDelay (1000 , false ); // 1 ms
293
- doubleOpenWithDelay (10000 , false ); // 10 ms
294
- doubleOpenWithDelay (100000 , false ); // 100 ms
295
+ doubleOpenWithDelay (std::chrono::microseconds ( 0 ) , false );
296
+ doubleOpenWithDelay (std::chrono::milliseconds ( 1 ) , false );
297
+ doubleOpenWithDelay (std::chrono::milliseconds ( 10 ) , false );
298
+ doubleOpenWithDelay (std::chrono::milliseconds ( 100 ) , false );
295
299
}
0 commit comments