Software /
code /
prosody
Annotate
spec/core_storagemanager.lua @ 9438:916bee81eb7e
net.server_epoll: Make :set_send a noop, should fix net.adns
This is also a noop in server_event. Supposedly meant to prevent
buffered writes from being sent to the socket, but that path becomes
unreachable when net.adns replaces the public send method
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 06 Oct 2018 17:50:41 +0200 |
parent | 9389:9ae575efbb1f |
rev | line source |
---|---|
9389
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local server = require "net.server_select"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 package.loaded["net.server"] = server; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local function mock_prosody() |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 _G.prosody = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 core_post_stanza = function () end; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 events = require "util.events".new(); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 hosts = {}; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 paths = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 data = "./data"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 end |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local configs = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 internal = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 storage = "internal"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 sqlite = { |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 storage = "sql"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 sql = { driver = "SQLite3", database = "prosody-tests.sqlite" }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local test_host = "storage-unit-tests.invalid"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 describe("storagemanager", function () |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 for _, backend in ipairs({ "internal", "sqlite" }) do |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local tagged_name = "#"..backend; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 if backend ~= configs[backend].storage then |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 tagged_name = tagged_name.." #"..configs[backend].storage; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 insulate(tagged_name.." #storage backend", function () |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 mock_prosody(); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local config = require "core.configmanager"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 local sm = require "core.storagemanager"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local hm = require "core.hostmanager"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local mm = require "core.modulemanager"; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 -- Simple check to ensure insulation is working correctly |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 assert.is_nil(config.get(test_host, "storage")); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 local backend_config = configs[backend]; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 for k, v in pairs(backend_config) do |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 config.set(test_host, k, v); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 end |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 assert(hm.activate(test_host, {})); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 sm.initialize_host(test_host); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 assert(mm.load(test_host, "storage_"..backend_config.storage)); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 -- These tests rely on being executed in order, disable any order |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 -- randomization for this block |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 randomize(false); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 local store; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 it("may open a store", function () |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 store = assert(sm.open(test_host, "test")); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 local simple_data = { foo = "bar" }; |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 it("may set data for a user", function () |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 assert(store:set("user9999", simple_data)); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 it("may get data for a user", function () |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 assert.same(simple_data, assert(store:get("user9999"))); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 end); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 it("may remove data for a user", function () |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 assert(store:set("user9999", nil)); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 local ret, err = store:get("user9999"); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 assert.is_nil(ret); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 assert.is_nil(err); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 end); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 end); |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 end |
9ae575efbb1f
Add storage tests (currently only internal and sqlite)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 end); |