Repository navigation
Expand file tree
/
Copy pathtest_verbose_multi.jl
More file actions
129 lines (108 loc) · 4.02 KB
/
Copy pathtest_verbose_multi.jl
File metadata and controls
129 lines (108 loc) · 4.02 KB
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
#!/usr/bin/env julia
# Test verbose mode with multi-instance LLMBenchMCPServer
using Sockets
using JSON
using Base.Threads
println("Testing verbose mode with multi-instance server...")
# Start the server with verbose and multi flags
server_cmd = `julia --project=. -m LLMBenchMCPServer LLMBenchSimple --socket --multi --verbose --direct`
println("Starting server with command: $server_cmd")
server_proc = run(pipeline(server_cmd, stdout=stdout, stderr=stderr), wait=false)
# Wait for server to start and create socket
sleep(3)
# Look for actual socket files
socket_files = filter(f -> startswith(f, "mcp_LLMBenchSimple"), readdir("/tmp"))
if !isempty(socket_files)
# Sort by creation time and use the latest one
sort!(socket_files, by=f->mtime(joinpath("/tmp", f)), rev=true)
socket_path = joinpath("/tmp", socket_files[1])
println("Found socket: $socket_path")
else
println("ERROR: No socket file found!")
kill(server_proc)
exit(1)
end
# Test function to send a request
function send_request(socket, request)
println(socket, JSON.json(request))
flush(socket)
response_line = readline(socket)
return JSON.parse(response_line)
end
# Connect two clients simultaneously
println("\n=== Testing with two simultaneous connections ===\n")
try
# Client 1
println("Client 1: Connecting to $socket_path")
client1 = connect(socket_path)
# Client 2
println("Client 2: Connecting to $socket_path")
client2 = connect(socket_path)
# Initialize both clients
println("\nClient 1: Sending initialize request")
init_request = Dict(
"jsonrpc" => "2.0",
"method" => "initialize",
"params" => Dict(
"protocolVersion" => "2024-11-05",
"capabilities" => Dict(),
"clientInfo" => Dict("name" => "test-client-1", "version" => "1.0")
),
"id" => 1
)
response1 = send_request(client1, init_request)
println("Client 1: Received response: ", response1["result"]["serverInfo"]["name"])
println("\nClient 2: Sending initialize request")
init_request["params"]["clientInfo"]["name"] = "test-client-2"
init_request["id"] = 1
response2 = send_request(client2, init_request)
println("Client 2: Received response: ", response2["result"]["serverInfo"]["name"])
# List tools from both clients
println("\nClient 1: Listing tools")
list_tools_request = Dict(
"jsonrpc" => "2.0",
"method" => "tools/list",
"params" => Dict(),
"id" => 2
)
tools1 = send_request(client1, list_tools_request)
println("Client 1: Found $(length(tools1["result"]["tools"])) tools")
println("\nClient 2: Listing tools")
tools2 = send_request(client2, list_tools_request)
println("Client 2: Found $(length(tools2["result"]["tools"])) tools")
# Setup problem on both clients with different problem IDs
println("\nClient 1: Setting up problem 'test_problem_1'")
setup_request = Dict(
"jsonrpc" => "2.0",
"method" => "tools/call",
"params" => Dict(
"name" => "setup_problem",
"arguments" => Dict("problem_id" => "test_problem_1")
),
"id" => 3
)
setup1 = send_request(client1, setup_request)
println("Client 1: Problem setup complete")
println("\nClient 2: Setting up problem 'test_problem_2'")
setup_request["params"]["arguments"]["problem_id"] = "test_problem_2"
setup2 = send_request(client2, setup_request)
println("Client 2: Problem setup complete")
# Close connections
println("\nClosing connections...")
close(client1)
close(client2)
println("\n=== Test completed successfully ===")
catch e
println("Error during test: $e")
rethrow(e)
finally
# Kill the server
kill(server_proc)
sleep(1)
end
println("\nVerbose mode test complete!")
println("You should see detailed logging output above including:")
println("- Connection establishment messages")
println("- Incoming request logs")
println("- Outgoing response logs")
println("- Connection closure messages")