|
| 1 | +// Copyright 2025 International Digital Economy Academy |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +///| |
| 16 | +test "peer close connection" { |
| 17 | + let port = 4208 |
| 18 | + @async.with_event_loop(fn(root) { |
| 19 | + // server |
| 20 | + root.spawn_bg(fn() { |
| 21 | + let server = @socket.TCPServer::new( |
| 22 | + @socket.Addr::parse("127.0.0.1:\{port}"), |
| 23 | + ) |
| 24 | + defer server.close() |
| 25 | + let (conn, _) = server.accept() |
| 26 | + defer conn.close() |
| 27 | + let server = @tls.TLS::server( |
| 28 | + conn, |
| 29 | + private_key_file="test_keys/key.pem", |
| 30 | + private_key_type=PEM, |
| 31 | + certificate_file="test_keys/cert.pem", |
| 32 | + certificate_type=PEM, |
| 33 | + ) |
| 34 | + defer server.close() |
| 35 | + @async.sleep(100) |
| 36 | + // the server already closed the connection |
| 37 | + server.shutdown() |
| 38 | + }) |
| 39 | + // client |
| 40 | + root.spawn_bg(fn() { |
| 41 | + let conn = @socket.TCP::connect(@socket.Addr::parse("127.0.0.1:\{port}")) |
| 42 | + defer conn.close() |
| 43 | + let client = @tls.TLS::client(conn, verify=false) |
| 44 | + defer client.close() |
| 45 | + @async.sleep(50) |
| 46 | + // close the underlying connection directly |
| 47 | + }) |
| 48 | + }) |
| 49 | +} |
0 commit comments