Mercurial > prosody-hg
annotate spec/util_error_spec.lua @ 10486:479e96e554c8
net.server_epoll: Add debug logging for delayed reading
In :onreadable, if there is still buffered incoming data after reading
from the socket (as indicated by the :dirty method, usually because
LuaSocket has an 8k buffer that's full but it read a smaller amount),
another attempt to read is scheduled via this :pausefor method. This is
also called from some other places where it would be pointless to read
because there shouldn't be any data.
In the delayed read case, this should report that the socket is "dirty".
If it reports that the socket is "clean" then the question is where
the buffer contents went?
If this doesn't get logged after the scheduled time (0.000001s by
default) then this would suggests a problem with timer or scheduling.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 07 Dec 2019 19:05:10 +0100 |
| parents | 744ca71a49f7 |
| children | 0b68697450c5 |
| rev | line source |
|---|---|
| 10101 | 1 local errors = require "util.error" |
| 2 | |
| 3 describe("util.error", function () | |
| 4 describe("new()", function () | |
| 5 it("works", function () | |
| 6 local err = errors.new("bork", "bork bork"); | |
| 7 assert.not_nil(err); | |
| 8 assert.equal("cancel", err.type); | |
| 9 assert.equal("undefined-condition", err.condition); | |
| 10 assert.same("bork bork", err.context); | |
| 11 end); | |
| 12 | |
| 13 describe("templates", function () | |
| 14 it("works", function () | |
| 15 local templates = { | |
| 16 ["fail"] = { | |
| 17 type = "wait", | |
| 18 condition = "internal-server-error", | |
|
10365
744ca71a49f7
util.error: Add well-known field 'code' in error templates
Kim Alvefur <zash@zash.se>
parents:
10101
diff
changeset
|
19 code = 555; |
| 10101 | 20 }; |
| 21 }; | |
| 22 local err = errors.new("fail", { traceback = "in some file, somewhere" }, templates); | |
| 23 assert.equal("wait", err.type); | |
| 24 assert.equal("internal-server-error", err.condition); | |
|
10365
744ca71a49f7
util.error: Add well-known field 'code' in error templates
Kim Alvefur <zash@zash.se>
parents:
10101
diff
changeset
|
25 assert.equal(555, err.code); |
| 10101 | 26 assert.same({ traceback = "in some file, somewhere" }, err.context); |
| 27 end); | |
| 28 end); | |
| 29 | |
| 30 end); | |
| 31 | |
| 32 describe("is_err()", function () | |
| 33 it("works", function () | |
| 34 assert.truthy(errors.is_err(errors.new())); | |
| 35 assert.falsy(errors.is_err("not an error")); | |
| 36 end); | |
| 37 end); | |
| 38 | |
| 39 describe("coerce", function () | |
| 40 it("works", function () | |
| 41 local ok, err = errors.coerce(nil, "it dun goofed"); | |
| 42 assert.is_nil(ok); | |
| 43 assert.truthy(errors.is_err(err)) | |
| 44 end); | |
| 45 end); | |
| 46 | |
| 47 describe("from_stanza", function () | |
| 48 it("works", function () | |
| 49 local st = require "util.stanza"; | |
| 50 local m = st.message({ type = "chat" }); | |
| 51 local e = st.error_reply(m, "modify", "bad-request"); | |
| 52 local err = errors.from_stanza(e); | |
| 53 assert.truthy(errors.is_err(err)); | |
| 54 assert.equal("modify", err.type); | |
| 55 assert.equal("bad-request", err.condition); | |
| 56 assert.equal(e, err.context.stanza); | |
| 57 end); | |
| 58 end); | |
| 59 | |
| 60 describe("__tostring", function () | |
| 61 it("doesn't throw", function () | |
| 62 assert.has_no.errors(function () | |
| 63 -- See 6f317e51544d | |
| 64 tostring(errors.new()); | |
| 65 end); | |
| 66 end); | |
| 67 end); | |
| 68 | |
| 69 end); | |
| 70 |
