Software / code / prosody
Annotate
spec/util_bitcompat_spec.lua @ 13765:7c57fb2ffbb0 13.0
mod_websocket: Merge session close handling changes from mod_c2s (bug fixes)
This should bring some fixes and general robustness that mod_websocket had
missed out on. The duplicated code here is not at all ideal. To prevent this
happening again, we should figure out how to have the common logic in a single
place, while still being able to do the websocket-specific parts that we need.
The main known bug that this fixes is that it's possible for a session to get
into a non-destroyable state. For example, if we try to session:close() a
hibernating session, then session.conn is nil and the function will simply
return without doing anything. In the mod_c2s code we already handle this, and
just destroy the session. But if a hibernating websocket session is never
resumed or becomes non-resumable, it will become immortal!
By merging the fix from mod_c2s, the session should now be correctly
destroyed.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 11 Mar 2025 18:44:40 +0000 |
| parent | 13449:9912baa541c0 |
| rev | line source |
|---|---|
|
12366
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 describe("util.bitcompat", function () |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- bitcompat will pass through to an appropriate implementation. Our |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- goal here is to check that whatever implementation is in use passes |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- these basic sanity checks. |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local bit = require "util.bitcompat"; |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 it("bor works", function () |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 assert.equal(0xF0FF, bit.bor(0xF000, 0x00F0, 0x000F)); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 end); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 it("band works", function () |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 assert.equal(0x0F, bit.band(0xFF, 0x1F, 0x0F)); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 end); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 it("bxor works", function () |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 assert.equal(0x13, bit.bxor(0x10, 0x0F, 0x0C)); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 it("rshift works", function () |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 assert.equal(0x0F, bit.rshift(0xFF, 4)); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 it("lshift works", function () |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 assert.equal(0xFF00, bit.lshift(0xFF, 8)); |
|
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end); |
|
13449
9912baa541c0
util.bit53: Add bnot() method
Matthew Wild <mwild1@gmail.com>
parents:
12366
diff
changeset
|
27 |
|
9912baa541c0
util.bit53: Add bnot() method
Matthew Wild <mwild1@gmail.com>
parents:
12366
diff
changeset
|
28 it("bnot works", function () |
|
9912baa541c0
util.bit53: Add bnot() method
Matthew Wild <mwild1@gmail.com>
parents:
12366
diff
changeset
|
29 assert.equal(0x0000FF00, bit.band(0xFFFFFFFF, bit.bnot(0xFFFF00FF))); |
|
9912baa541c0
util.bit53: Add bnot() method
Matthew Wild <mwild1@gmail.com>
parents:
12366
diff
changeset
|
30 end); |
|
12366
c640717e01ca
util.bitcompat: Add some simple tests
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end); |