Mercurial > prosody-modules
comparison mod_test_data/mod_test_data.lua @ 3357:af824168729a
mod_test_data: New module to generate test data in Prosody's data store
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 15 Oct 2018 14:27:20 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3356:31e113823463 | 3357:af824168729a |
---|---|
1 local users = { "fezziwig", "badger", "nupkins", "pumblechook", "rouncewell" }; | |
2 local host = "localhost"; | |
3 | |
4 local id = require "util.id"; | |
5 local st = require "util.stanza"; | |
6 local sm = require "core.storagemanager"; | |
7 | |
8 -- Return a random number from 1..max excluding n | |
9 function random_other(n, max) return ((math.random(1, max-1)+(n-1))%max)+1; end | |
10 | |
11 local new_time; | |
12 do | |
13 local _current_time = os.time(); | |
14 function new_time() | |
15 _current_time = _current_time + math.random(1, 3600); | |
16 return _current_time; | |
17 end | |
18 end | |
19 | |
20 function module.command(arg) --luacheck: ignore arg | |
21 sm.initialize_host(host); | |
22 local archive = sm.open(host, "archive", "archive"); | |
23 | |
24 for _ = 1, 100000 do | |
25 local random = math.random(1, #users); | |
26 local user, contact = users[random], users[random_other(random, #users)]; | |
27 local user_jid, contact_jid = user.."@"..host, contact.."@"..host; | |
28 | |
29 local stanza = st.message({ to = contact_jid, from = user_jid, type="chat" }) | |
30 :tag("body"):text(id.long()); | |
31 | |
32 archive:append(user, nil, stanza, new_time(), contact_jid) | |
33 | |
34 local stanza2 = st.clone(stanza); | |
35 stanza2.attr.from, stanza2.attr.to = stanza.attr.to, stanza.attr.from; | |
36 archive:append(contact, nil, stanza2, new_time(), user_jid) | |
37 end | |
38 end |