This is an automated email from the ASF dual-hosted git repository.

zyxxoo pushed a commit to branch refactor/rust-rewrite-design
in repository https://gitbox.apache.org/repos/asf/hugegraph.git


The following commit(s) were added to refs/heads/refactor/rust-rewrite-design 
by this push:
     new 9e01d9676 refactor(oracle): isolate history capture routine
9e01d9676 is described below

commit 9e01d9676f8e3175d8eac8fb1de0414931b5fb1b
Author: vaughn <[email protected]>
AuthorDate: Sun Sep 13 16:01:33 2026 +0800

    refactor(oracle): isolate history capture routine
---
 tools/raft-linearizability/capture_history.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/tools/raft-linearizability/capture_history.py 
b/tools/raft-linearizability/capture_history.py
index f41a5470a..32d8879fa 100755
--- a/tools/raft-linearizability/capture_history.py
+++ b/tools/raft-linearizability/capture_history.py
@@ -2,16 +2,17 @@
 """Capture a small register history from an HTTP endpoint."""
 import argparse, json, time, urllib.request
 
-def main():
-    ap=argparse.ArgumentParser(); ap.add_argument('url'); 
ap.add_argument('--value',type=int,default=1); 
ap.add_argument('--output',required=True); a=ap.parse_args()
+def capture(url, value):
     ops=[]
     def call(op, value=None):
         ident=f'op-{len(ops)+1}'; start=time.monotonic_ns()
-        req=urllib.request.Request(a.url, method='GET' if op=='read' else 
'POST', data=None if op=='read' else json.dumps({'value':value}).encode(), 
headers={'Content-Type':'application/json'})
-        try:
-            with urllib.request.urlopen(req, timeout=10) as r: 
body=r.read().decode(); observed=value if op=='write' else 
json.loads(body).get('value')
-        finally: end=time.monotonic_ns()
-        
ops.append({'id':ident,'op':op,'value':observed,'start':start,'end':end})
-    call('write', a.value); call('read')
+        req=urllib.request.Request(url, method='GET' if op=='read' else 
'POST', data=None if op=='read' else json.dumps({'value':value}).encode(), 
headers={'Content-Type':'application/json'})
+        with urllib.request.urlopen(req, timeout=10) as r: 
body=r.read().decode(); observed=value if op=='write' else 
json.loads(body).get('value')
+        
ops.append({'id':ident,'op':op,'value':observed,'start':start,'end':time.monotonic_ns()})
+    call('write', value); call('read'); return ops
+
+def main():
+    ap=argparse.ArgumentParser(); ap.add_argument('url'); 
ap.add_argument('--value',type=int,default=1); 
ap.add_argument('--output',required=True); a=ap.parse_args()
+    ops=capture(a.url, a.value)
     with open(a.output,'w',encoding='utf-8') as f: json.dump(ops,f,indent=2)
 if __name__=='__main__': main()

Reply via email to