]> source.dussan.org Git - rspamd.git/commitdiff
[Test] statistics: per-user 4789/head
authorAndrew Lewis <nerf@judo.za.org>
Wed, 24 Jan 2024 23:58:50 +0000 (01:58 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Wed, 24 Jan 2024 23:58:50 +0000 (01:58 +0200)
test/functional/cases/110_statistics/090-peruser.robot [new file with mode: 0644]
test/functional/cases/110_statistics/100-redis-keyed-siphash.robot [new file with mode: 0644]
test/functional/cases/110_statistics/110-redis-keyed-xxhash.robot [new file with mode: 0644]
test/functional/cases/110_statistics/200-redis-plain-siphash.robot [new file with mode: 0644]
test/functional/cases/110_statistics/210-redis-plain-xxhash.robot [new file with mode: 0644]
test/functional/cases/110_statistics/lib.robot
test/functional/cases/110_statistics/redis-keyed-siphash.robot [deleted file]
test/functional/cases/110_statistics/redis-keyed-xxhash.robot [deleted file]
test/functional/cases/110_statistics/redis-plain-siphash.robot [deleted file]
test/functional/cases/110_statistics/redis-plain-xxhash.robot [deleted file]
test/functional/configs/stats.conf

diff --git a/test/functional/cases/110_statistics/090-peruser.robot b/test/functional/cases/110_statistics/090-peruser.robot
new file mode 100644 (file)
index 0000000..cd8f3ac
--- /dev/null
@@ -0,0 +1,15 @@
+*** Settings ***
+Suite Setup     Rspamd Redis Setup
+Suite Teardown  Rspamd Redis Teardown
+Resource        lib.robot
+
+*** Variables ***
+${RSPAMD_REDIS_SERVER}    ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
+${RSPAMD_STATS_PER_USER}  true
+
+*** Test Cases ***
+Learn
+  Learn Test  test@example.com
+
+Relearn
+  Relearn Test  test@example.com
diff --git a/test/functional/cases/110_statistics/100-redis-keyed-siphash.robot b/test/functional/cases/110_statistics/100-redis-keyed-siphash.robot
new file mode 100644 (file)
index 0000000..d889502
--- /dev/null
@@ -0,0 +1,16 @@
+*** Settings ***
+Suite Setup     Rspamd Redis Setup
+Suite Teardown  Rspamd Redis Teardown
+Resource        lib.robot
+
+*** Variables ***
+${RSPAMD_REDIS_SERVER}  ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
+${RSPAMD_STATS_HASH}    siphash
+${RSPAMD_STATS_KEY}     ${RSPAMD_KEY_PVT1}
+
+*** Test Cases ***
+Learn
+  Learn Test
+
+Relearn
+  Relearn Test
diff --git a/test/functional/cases/110_statistics/110-redis-keyed-xxhash.robot b/test/functional/cases/110_statistics/110-redis-keyed-xxhash.robot
new file mode 100644 (file)
index 0000000..928a9ea
--- /dev/null
@@ -0,0 +1,16 @@
+*** Settings ***
+Suite Setup     Rspamd Redis Setup
+Suite Teardown  Rspamd Redis Teardown
+Resource        lib.robot
+
+*** Variables ***
+${RSPAMD_REDIS_SERVER}  ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
+${RSPAMD_STATS_HASH}    xxhash
+${RSPAMD_STATS_KEY}     ${RSPAMD_KEY_PVT1}
+
+*** Test Cases ***
+Learn
+  Learn Test
+
+Relearn
+  Relearn Test
diff --git a/test/functional/cases/110_statistics/200-redis-plain-siphash.robot b/test/functional/cases/110_statistics/200-redis-plain-siphash.robot
new file mode 100644 (file)
index 0000000..790a63e
--- /dev/null
@@ -0,0 +1,15 @@
+*** Settings ***
+Suite Setup     Rspamd Redis Setup
+Suite Teardown  Rspamd Redis Teardown
+Resource        lib.robot
+
+*** Variables ***
+${RSPAMD_REDIS_SERVER}  ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
+${RSPAMD_STATS_HASH}    siphash
+
+*** Test Cases ***
+Learn
+  Learn Test
+
+Relearn
+  Relearn Test
diff --git a/test/functional/cases/110_statistics/210-redis-plain-xxhash.robot b/test/functional/cases/110_statistics/210-redis-plain-xxhash.robot
new file mode 100644 (file)
index 0000000..55e7524
--- /dev/null
@@ -0,0 +1,15 @@
+*** Settings ***
+Suite Setup     Rspamd Redis Setup
+Suite Teardown  Rspamd Redis Teardown
+Resource        lib.robot
+
+*** Variables ***
+${RSPAMD_REDIS_SERVER}  ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
+${RSPAMD_STATS_HASH}    xxhash
+
+*** Test Cases ***
+Learn
+  Learn Test
+
+Relearn
+  Relearn Test
index c6fad2b2fc5298a758661af14965aa865f5b84b2..792806300e4b665999a6a1111483c688a0580d38 100644 (file)
@@ -4,15 +4,16 @@ Resource        ${RSPAMD_TESTDIR}/lib/rspamd.robot
 Variables       ${RSPAMD_TESTDIR}/lib/vars.py
 
 *** Variables ***
-${CONFIG}                ${RSPAMD_TESTDIR}/configs/stats.conf
-${MESSAGE_HAM}           ${RSPAMD_TESTDIR}/messages/ham.eml
-${MESSAGE_SPAM}          ${RSPAMD_TESTDIR}/messages/spam_message.eml
-${REDIS_SCOPE}           Suite
-${RSPAMD_REDIS_SERVER}   null
-${RSPAMD_SCOPE}          Suite
-${RSPAMD_STATS_BACKEND}  redis
-${RSPAMD_STATS_HASH}     null
-${RSPAMD_STATS_KEY}      null
+${CONFIG}                 ${RSPAMD_TESTDIR}/configs/stats.conf
+${MESSAGE_HAM}            ${RSPAMD_TESTDIR}/messages/ham.eml
+${MESSAGE_SPAM}           ${RSPAMD_TESTDIR}/messages/spam_message.eml
+${REDIS_SCOPE}            Suite
+${RSPAMD_REDIS_SERVER}    null
+${RSPAMD_SCOPE}           Suite
+${RSPAMD_STATS_BACKEND}   redis
+${RSPAMD_STATS_HASH}      null
+${RSPAMD_STATS_KEY}       null
+${RSPAMD_STATS_PER_USER}  ${EMPTY}
 
 *** Keywords ***
 Broken Learn Test
@@ -26,24 +27,41 @@ Empty Part Test
   Scan File  ${MESSAGE}
   Expect Symbol  BAYES_SPAM
 
+Learn
+  [Arguments]  ${user}  ${class}  ${message}
+  IF  "${user}"
+    ${result} =  Run Rspamc  -d  ${user}  -h  ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER}  learn_${class}  ${message}
+  ELSE
+    ${result} =  Run Rspamc  -h  ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER}  learn_${class}  ${message}
+  END
+  Check Rspamc  ${result}
+
 Learn Test
+  [Arguments]  ${user}=${EMPTY}
   Set Suite Variable  ${RSPAMD_STATS_LEARNTEST}  0
-  ${result} =  Run Rspamc  -h  ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER}  learn_spam  ${MESSAGE_SPAM}
-  ${result} =  Run Rspamc  -h  ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER}  learn_ham  ${MESSAGE_HAM}
-  Check Rspamc  ${result}
-  Scan File  ${MESSAGE_SPAM}
+  Set Test Variable  ${kwargs}  &{EMPTY}
+  IF  "${user}"
+    Set To Dictionary  ${kwargs}  Deliver-To=${user}
+  END
+  Learn  ${user}  spam  ${MESSAGE_SPAM}
+  Learn  ${user}  ham  ${MESSAGE_HAM}
+  Scan File  ${MESSAGE_SPAM}  &{kwargs}
   Expect Symbol  BAYES_SPAM
-  Scan File  ${MESSAGE_HAM}
+  Scan File  ${MESSAGE_HAM}  &{kwargs}
   Expect Symbol  BAYES_HAM
   Set Suite Variable  ${RSPAMD_STATS_LEARNTEST}  1
 
 Relearn Test
+  [Arguments]  ${user}=${EMPTY}
   IF  ${RSPAMD_STATS_LEARNTEST} == 0
     Fail  "Learn test was not run"
   END
-  ${result} =  Run Rspamc  -h  ${RSPAMD_LOCAL_ADDR}:${RSPAMD_PORT_CONTROLLER}  learn_ham  ${MESSAGE_SPAM}
-  Check Rspamc  ${result}
-  Scan File  ${MESSAGE_SPAM}
+  Learn  ${user}  ham  ${MESSAGE_SPAM}
+  Set Test Variable  ${kwargs}  &{EMPTY}
+  IF  "${user}"
+    Set To Dictionary  ${kwargs}  Deliver-To=${user}
+  END
+  Scan File  ${MESSAGE_SPAM}  &{kwargs}
   ${pass} =  Run Keyword And Return Status  Expect Symbol  BAYES_HAM
   IF  ${pass}
     Pass Execution  What Me Worry
diff --git a/test/functional/cases/110_statistics/redis-keyed-siphash.robot b/test/functional/cases/110_statistics/redis-keyed-siphash.robot
deleted file mode 100644 (file)
index d889502..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-*** Settings ***
-Suite Setup     Rspamd Redis Setup
-Suite Teardown  Rspamd Redis Teardown
-Resource        lib.robot
-
-*** Variables ***
-${RSPAMD_REDIS_SERVER}  ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
-${RSPAMD_STATS_HASH}    siphash
-${RSPAMD_STATS_KEY}     ${RSPAMD_KEY_PVT1}
-
-*** Test Cases ***
-Learn
-  Learn Test
-
-Relearn
-  Relearn Test
diff --git a/test/functional/cases/110_statistics/redis-keyed-xxhash.robot b/test/functional/cases/110_statistics/redis-keyed-xxhash.robot
deleted file mode 100644 (file)
index 928a9ea..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-*** Settings ***
-Suite Setup     Rspamd Redis Setup
-Suite Teardown  Rspamd Redis Teardown
-Resource        lib.robot
-
-*** Variables ***
-${RSPAMD_REDIS_SERVER}  ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
-${RSPAMD_STATS_HASH}    xxhash
-${RSPAMD_STATS_KEY}     ${RSPAMD_KEY_PVT1}
-
-*** Test Cases ***
-Learn
-  Learn Test
-
-Relearn
-  Relearn Test
diff --git a/test/functional/cases/110_statistics/redis-plain-siphash.robot b/test/functional/cases/110_statistics/redis-plain-siphash.robot
deleted file mode 100644 (file)
index 790a63e..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-*** Settings ***
-Suite Setup     Rspamd Redis Setup
-Suite Teardown  Rspamd Redis Teardown
-Resource        lib.robot
-
-*** Variables ***
-${RSPAMD_REDIS_SERVER}  ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
-${RSPAMD_STATS_HASH}    siphash
-
-*** Test Cases ***
-Learn
-  Learn Test
-
-Relearn
-  Relearn Test
diff --git a/test/functional/cases/110_statistics/redis-plain-xxhash.robot b/test/functional/cases/110_statistics/redis-plain-xxhash.robot
deleted file mode 100644 (file)
index 55e7524..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-*** Settings ***
-Suite Setup     Rspamd Redis Setup
-Suite Teardown  Rspamd Redis Teardown
-Resource        lib.robot
-
-*** Variables ***
-${RSPAMD_REDIS_SERVER}  ${RSPAMD_REDIS_ADDR}:${RSPAMD_REDIS_PORT}
-${RSPAMD_STATS_HASH}    xxhash
-
-*** Test Cases ***
-Learn
-  Learn Test
-
-Relearn
-  Relearn Test
index bfa39b4268bb57cc0838df79babad72604d8c71f..ba6a5fe9c750c6806227d8523951609232bfd069 100644 (file)
@@ -71,6 +71,14 @@ classifier {
        cache {
                server = {= env.REDIS_SERVER =}
        }
+
+       {% if env.STATS_PER_USER ~= '' %}
+       per_user = <<EOD
+return function(task)
+  return task:get_principal_recipient()
+end
+EOD;
+       {% endif %}
 }
 lua = "{= env.TESTDIR =}/lua/test_coverage.lua";