Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

44
LINES

< > BotCompany Repo | #1009330 // Test evalWithTimeout [OK]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2176L/15K/50K).

1  
!7
2  
3  
p {
4  
  // Easy case - finishes in time
5  
  
6  
  print("Test 1");
7  
  Either<O, Thread> e = evalWithTimeout(1500, f f);
8  
  assertEquals(0, l(evalWithTimeout_inTime));
9  
  while (l(evalWithTimeout_allThreads) > 0) sleep(1);
10  
  assertEqualsVerbose("yo!", e.a());
11  
  
12  
  // Medium case - is in sleep or wait, interruptible
13  
  
14  
  print("Test 2");
15  
  e = evalWithTimeout(500, f f);
16  
  assertEquals(0, l(evalWithTimeout_inTime));
17  
  assertTrue(e.isB());
18  
  assertTrue(l(evalWithTimeout_allThreads) <= 1);
19  
  
20  
  while (l(evalWithTimeout_allThreads) > 0) sleep(1);
21  
  
22  
  // Hard case - busy computing, doesn't call ping
23  
  
24  
  print("Test 3");
25  
  e = evalWithTimeout(500, f g);
26  
  assertEquals(0, l(evalWithTimeout_inTime));
27  
  sleep(10);
28  
  assertEquals(1, l(evalWithTimeout_allThreads));
29  
  assertTrue(e.isB());
30  
  
31  
  while (l(evalWithTimeout_allThreads) > 0) sleep(1);
32  
  
33  
  print("All OK");
34  
}
35  
36  
static S f() {
37  
  sleep(1000);
38  
  ret print("yo!");
39  
}
40  
41  
static S g() {
42  
  busySleepSeconds_noPing(1);
43  
  ret print("yo!");
44  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009330
Snippet name: Test evalWithTimeout [OK]
Eternal ID of this version: #1009330/14
Text MD5: 501f83fb11cfa7135b40f9a8a8c18980
Transpilation MD5: 45b16c471370591c457afe89c68ad37b
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-31 23:48:30
Source code size: 1026 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 489 / 615
Version history: 13 change(s)
Referenced in: [show references]