Tcl Library Source Code

View Ticket
Login
Ticket UUID: f4efd0f591b6bbdcfaadf98179e282665bc60b9b
Title: websocket testsuite is broken
Type: Bug Version: 1.5
Submitter: aku Created on: 2023-01-30 13:32:40
Subsystem: websocket Assigned To: emmanuel
Priority: 7 High Severity: Severe
Status: Open Last Modified: 2023-07-17 10:02:34
Resolution: None Closed By: nobody
    Closed on:
Description:
The websocket testsuite is broken.
Three tests fails (1.3, 1.4, and 2.1).

Investigation into the failure of 1.3 shows a mismatch of expectations somewhere (package implementation, or package tests). It is suspected that the other tests suffer from similar issues, maybe even the very same.

The package uses the __-keepalive__ option to ensure that the HTTP socket is kept open for it to take over. This option however also instructs the underlying __http__ package that an any earlier open socket to the same destination can/should be reused.

The failing test assumes that such a reuse will not happen, and thus fails, because reuse does happen.

The mismatch can be in the test, with its assumption of non-reuse.

It can also be seen in the implementation, which on the one hand asks for socket reuse, as a means of taking the socket over after initial communication, yet also not wanting reuse of such sockets after it has taken them over. The issue there is that the __http__ package is never informed of __websocket__ taking ownership for the socket from it. To `http` the connection still belongs to it, and is a valid target for reuse by future __geturl__ requests.
User Comments: pointsman added on 2023-07-17 10:02:34:
I see the something as aku (thoug not exactly the same) under linux. More specific, if I run

tclsh8.6 sak.tcl test run  -v websocket

the tests 1.3 and 1.4 fail:

==== example-1.3 Open second websocket - require different socket FAILED
==== Contents of test case:

    wsExpectHandler $expectNum
    set ws2 [::websocket::open $wsUrl wsOutputHandler]
    if {$ws1 eq $ws2} {
        set res "Both sockets are $ws1"
    } else {
        set res "Sockets differ: $ws1 and $ws2"
    }

---- Result was:
Both sockets are sock564c2ae56eb0
---- Result should have been (glob matching):
Sockets differ: *
==== example-1.3 FAILED

---- example-1.4 start


==== example-1.4 Open second websocket - usual server return FAILED
==== Contents of test case:

    wsExpectHandler $expectNum
    set ws2 [::websocket::open $wsUrl wsOutputHandler]
    if {$ws1 eq $ws2} {
        return -code error "Both sockets are $ws1"
    }
    wsSleep
    wsResetSleep
    wsSleep 1000
    string map [list $ws2 SOCKET] $wsOutput

---- Result was:
Both sockets are sock564c2ae3d7d0
---- Result should have been (glob matching):
SOCKET connect {}
SOCKET text {Request served by *}

==== example-1.4 FAILED


The test 2.1 passes for me.

With Tcl 8.5.19 and with Tcl 9 (almost recent trunk) all tests passes.

kjnash added on 2023-02-17 12:41:07:

(1) Using sak.tcl to run the tests

Which platform and Tcl version has the bug?

I cannot reproduce the bug. Building Tcl on Linux x86_64, and using sak.tcl to run the tests, all the tests pass.

Testing Tcllib db549a5ec8.
[tcllib]$ 
[tcllib]$ tclsh sak.tcl test shell add /usr/local/Tcl-8.6.13/bin/tclsh8.6  # official release 8.6.13
[tcllib]$ tclsh sak.tcl test shell add /usr/local/Tcl-8.6/bin/tclsh8.6     # core-8-6-branch 04cf08d26a
[tcllib]$ tclsh sak.tcl test shell add /usr/local/Tcl-8.7/bin/tclsh8.7     # core-8-branch 6349e0c2e1
[tcllib]$ 
[tcllib]$ tclsh sak.tcl test run websocket
[    ]  Starting ...l/Tcl-8.7/bin/tclsh8.7
[*   ]  [8.6.13] websocket !sourcing file /local/home/kjnash/projects/tcllib/modules/websocket/websocket.tcl
[    ]  [8.6.13] websocket ~~       T     5 P     5 S     0 F     0 @7s
[*   ]  [8.6.13] websocket !sourcing file /local/home/kjnash/projects/tcllib/modules/websocket/websocket.tcl
[    ]  [8.6.13] websocket ~~       T     5 P     5 S     0 F     0 @6s
[*   ]  [8.7a6]  websocket !sourcing file /local/home/kjnash/projects/tcllib/modules/websocket/websocket.tcl
[    ]  [8.7a6]  websocket ~~       T     5 P     5 S     0 F     0 @6s
Passed      15 of     15
Skipped      0 of     15
Failed       0 of     15
 #Errors      0
[    ]  ... Done

(2) Sourcing the test file in a Tcl interpreter.

The websocket module loads other Tcllib modules. The sak.tcl script allows this by setting ::auto_path to include the modules directory of the Tcllib that is being tested.

If the websocket.test script is modified to add the modules directory to ::auto_path, the tests also pass when sourcing the test file in a Tcl interpreter.

I will commit this revision to websocket.test. However, I expect that this is not the cause of your test failures because it causes all tests to fail - the test script fails when loading package websocket, before individual tests are executed.