# HG changeset patch # User Matthew Wild # Date 1539610040 -3600 # Node ID af824168729a7cd095242cf7f1a81d851bd30ddc # Parent 31e1138234633afbc5df1303b4603c6379ee2c9d mod_test_data: New module to generate test data in Prosody's data store diff -r 31e113823463 -r af824168729a mod_test_data/README.markdown --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_test_data/README.markdown Mon Oct 15 14:27:20 2018 +0100 @@ -0,0 +1,12 @@ +--- +description: Generate test data +labels: +- 'Stage-Alpha' +--- + +This module is of use to developers who want to fill their Prosody storage with +test data, e.g. for debugging, testing or performance measurements of Prosody or +client code. + +Currently it only supports filling MAM archives, but patches are welcome for other +functionality. diff -r 31e113823463 -r af824168729a mod_test_data/mod_test_data.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_test_data/mod_test_data.lua Mon Oct 15 14:27:20 2018 +0100 @@ -0,0 +1,38 @@ +local users = { "fezziwig", "badger", "nupkins", "pumblechook", "rouncewell" }; +local host = "localhost"; + +local id = require "util.id"; +local st = require "util.stanza"; +local sm = require "core.storagemanager"; + +-- Return a random number from 1..max excluding n +function random_other(n, max) return ((math.random(1, max-1)+(n-1))%max)+1; end + +local new_time; +do + local _current_time = os.time(); + function new_time() + _current_time = _current_time + math.random(1, 3600); + return _current_time; + end +end + +function module.command(arg) --luacheck: ignore arg + sm.initialize_host(host); + local archive = sm.open(host, "archive", "archive"); + + for _ = 1, 100000 do + local random = math.random(1, #users); + local user, contact = users[random], users[random_other(random, #users)]; + local user_jid, contact_jid = user.."@"..host, contact.."@"..host; + + local stanza = st.message({ to = contact_jid, from = user_jid, type="chat" }) + :tag("body"):text(id.long()); + + archive:append(user, nil, stanza, new_time(), contact_jid) + + local stanza2 = st.clone(stanza); + stanza2.attr.from, stanza2.attr.to = stanza.attr.to, stanza.attr.from; + archive:append(contact, nil, stanza2, new_time(), user_jid) + end +end