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

73
LINES

< > BotCompany Repo | #1001318 // Test case (start dependent VM and check if it reports its PID and program ID)

JavaX General Test Case [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2390L/16K/53K).

1  
!747
2  
3  
m {
4  
  static new Flag done;
5  
  static new Flag success;
6  
  static int myPort, vmPort;
7  
  
8  
  static long lastRun;
9  
  static boolean lastResult;
10  
11  
  static boolean keepVMAlive = false; // keep VM alive after test (set to false for production!)
12  
  
13  
  static S vmProgram = "#1001317";
14  
15  
  !include #1000915 // Flag
16  
  
17  
  p {
18  
    myPort = makeAndroid3("Test Case Master Bot.").port;
19  
    
20  
    // Start Dependent VM
21  
    nohupJavax(vmProgram.substring(1) + " " + myPort);
22  
    sleep();
23  
  }
24  
  
25  
  static void startTest() {
26  
    thread {
27  
      try {
28  
        DialogIO io = talkTo("localhost", vmPort);
29  
        print(io.readLine());
30  
        
31  
        io.sendLine("What is your process id?");
32  
        S s = io.readLine();
33  
        print("VM said: " + s);
34  
        int pid = parseInt(s);
35  
        print("PID: " + pid);
36  
        
37  
        if (!(pid != 0 && processIDExists("" + pid)))
38  
          fail(s);
39  
          
40  
        io.sendLine("What is the main program id?");
41  
        s = io.readLine();
42  
        if (parseSnippetID(s) != parseSnippetID(vmProgram))
43  
          fail(s);
44  
        
45  
        success.raise();
46  
      } catch (Throwable e) {
47  
        e.printStackTrace();
48  
      }
49  
      
50  
      done.raise(); // so dependent VM exits
51  
      
52  
      lastRun = now(); saveLocally("lastRun");
53  
      lastResult = success.isUp(); saveLocally("lastResult");
54  
      print(success.isUp() ? "TEST SUCCESS" : "TEST FAILURE");
55  
      
56  
      sendTestResult(success.isUp());
57  
    }
58  
  }
59  
  
60  
  static synchronized S answer(S s, L<S> history) {
61  
    new Matches m;
62  
    
63  
    if (match3("Master: My VM port is *", s, m)) {
64  
      if (vmPort == 0) {
65  
        vmPort = parseInt(unquote(m.m[0]));
66  
        startTest();
67  
      }
68  
      return "OK";
69  
    } if (match3("Master: Should I stay alive?", s))
70  
      return !keepVMAlive && done.isUp() ? "No." : "Yes.";
71  
    return null;
72  
  }
73  
}

download  show line numbers  debug dex  old transpilations   

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

Comments [hide]

ID Author/Program Comment Date
1164 #1001318 Success on teubizvjbppd 2015-11-02 17:51:49  delete 

add comment

Snippet ID: #1001318
Snippet name: Test case (start dependent VM and check if it reports its PID and program ID)
Eternal ID of this version: #1001318/1
Text MD5: 174912f5260e153918e2a9501c961bbb
Transpilation MD5: c7294b8ce67b3038611cc01805d4f573
Author: stefan
Category: javax
Type: JavaX General Test Case
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-11-02 17:51:08
Source code size: 1888 bytes / 73 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 969 / 1030
Referenced in: [show references]