commit f2cc671: [Test] Fix automatic training tests

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Nov 10 11:35:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-11-10 11:31:02 +0000
URL: https://github.com/rspamd/rspamd/commit/f2cc671ac5fa15c89a8a8f7410fdf0758bed9b4a (HEAD -> master)

[Test] Fix automatic training tests

---
 .../cases/330_neural/001_autotrain.robot           | 44 +++++++++++-----------
 test/functional/configs/neural.conf                |  2 +-
 test/functional/lua/neural.lua                     | 31 ++++++++-------
 3 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/test/functional/cases/330_neural/001_autotrain.robot b/test/functional/cases/330_neural/001_autotrain.robot
index a267416ff..4ca29f196 100644
--- a/test/functional/cases/330_neural/001_autotrain.robot
+++ b/test/functional/cases/330_neural/001_autotrain.robot
@@ -16,48 +16,48 @@ ${RSPAMD_URL_TLD}  ${RSPAMD_TESTDIR}/../lua/unit/test_tld.dat
 *** Test Cases ***
 Train
   Sleep  2s  Wait for redis mess
-  FOR    ${INDEX}    IN RANGE    0    10
-    Scan File  ${MESSAGE}  Settings={symbols_enabled = ["SPAM_SYMBOL"]}
-    Expect Symbol  SPAM_SYMBOL
-    Scan File  ${MESSAGE}  Settings={symbols_enabled = ["HAM_SYMBOL"]}
-    Expect Symbol  HAM_SYMBOL
+  FOR    ${INDEX}    IN RANGE    1    11
+    Scan File  ${MESSAGE}  Settings={symbols_enabled = ["SPAM_SYMBOL${INDEX}"]}
+    Expect Symbol  SPAM_SYMBOL${INDEX}
+    Scan File  ${MESSAGE}  Settings={symbols_enabled = ["HAM_SYMBOL${INDEX}"]}
+    Expect Symbol  HAM_SYMBOL${INDEX}
   END
 
 Check Neural HAM
   Sleep  2s  Wait for neural to be loaded
-  Scan File  ${MESSAGE}  Settings={symbols_enabled = ["HAM_SYMBOL"];groups_enabled=["neural"];symbols_disabled = ["NEURAL_LEARN"]}
+  Scan File  ${MESSAGE}  Settings={symbols_enabled = ["HAM_SYMBOL1","HAM_SYMBOL2","HAM_SYMBOL5"];groups_enabled=["neural"];symbols_disabled = ["NEURAL_LEARN"]}
   Expect Symbol  NEURAL_HAM_SHORT
   Do Not Expect Symbol  NEURAL_SPAM_SHORT
-  Expect Symbol  NEURAL_HAM_SHORT_PCA
-  Do Not Expect Symbol  NEURAL_SPAM_SHORT_PCA
+  #Expect Symbol  NEURAL_HAM_SHORT_PCA
+  #Do Not Expect Symbol  NEURAL_SPAM_SHORT_PCA
 
 Check Neural SPAM
-  Scan File  ${MESSAGE}  Settings={symbols_enabled = ["SPAM_SYMBOL"];groups_enabled=["neural"];symbols_disabled = ["NEURAL_LEARN"]}
+  Scan File  ${MESSAGE}  Settings={symbols_enabled = ["SPAM_SYMBOL2","SPAM_SYMBOL4","SPAM_SYMBOL6","SPAM_SYMBOL8"];groups_enabled=["neural"];symbols_disabled = ["NEURAL_LEARN"]}
   Expect Symbol  NEURAL_SPAM_SHORT
   Do Not Expect Symbol  NEURAL_HAM_SHORT
-  Expect Symbol  NEURAL_SPAM_SHORT_PCA
-  Do Not Expect Symbol  NEURAL_HAM_SHORT_PCA
+  #Expect Symbol  NEURAL_SPAM_SHORT_PCA
+  #Do Not Expect Symbol  NEURAL_HAM_SHORT_PCA
 
 
 Train INVERSE
-  FOR    ${INDEX}    IN RANGE    0    10
-    Scan File  ${MESSAGE}  Settings={symbols_enabled = ["SPAM_SYMBOL"]; SPAM_SYMBOL = -5;}
-    Expect Symbol  SPAM_SYMBOL
-    Scan File  ${MESSAGE}  Settings={symbols_enabled = ["HAM_SYMBOL"]; HAM_SYMBOL = 5;}
-    Expect Symbol  HAM_SYMBOL
+  FOR    ${INDEX}    IN RANGE    1    11
+    Scan File  ${MESSAGE}  Settings={symbols_enabled = ["SPAM_SYMBOL${INDEX}"]; SPAM_SYMBOL${INDEX} = -5;}
+    Expect Symbol  SPAM_SYMBOL${INDEX}
+    Scan File  ${MESSAGE}  Settings={symbols_enabled = ["HAM_SYMBOL${INDEX}"]; HAM_SYMBOL${INDEX} = 5;}
+    Expect Symbol  HAM_SYMBOL${INDEX}
   END
 
 Check Neural HAM INVERSE
   Sleep  2s  Wait for neural to be loaded
-  Scan File  ${MESSAGE}  Settings={symbols_enabled = ["HAM_SYMBOL"];groups_enabled=["neural"]}
+  Scan File  ${MESSAGE}  Settings={symbols_enabled = ["HAM_SYMBOL1","HAM_SYMBOL2","HAM_SYMBOL5"];groups_enabled=["neural"]}
   Expect Symbol  NEURAL_SPAM_SHORT
-  Expect Symbol  NEURAL_SPAM_SHORT_PCA
+  #Expect Symbol  NEURAL_SPAM_SHORT_PCA
   Do Not Expect Symbol  NEURAL_HAM_SHORT
-  Do Not Expect Symbol  NEURAL_HAM_SHORT_PCA
+  #Do Not Expect Symbol  NEURAL_HAM_SHORT_PCA
 
 Check Neural SPAM INVERSE
-  Scan File  ${MESSAGE}  Settings={symbols_enabled = ["SPAM_SYMBOL"];groups_enabled=["neural"]}
+  Scan File  ${MESSAGE}  Settings={symbols_enabled = ["SPAM_SYMBOL2","SPAM_SYMBOL4","SPAM_SYMBOL6","SPAM_SYMBOL8"];groups_enabled=["neural"]}
   Expect Symbol  NEURAL_HAM_SHORT
-  Expect Symbol  NEURAL_HAM_SHORT_PCA
+  #Expect Symbol  NEURAL_HAM_SHORT_PCA
   Do Not Expect Symbol  NEURAL_SPAM_SHORT
-  Do Not Expect Symbol  NEURAL_SPAM_SHORT_PCA
+  #Do Not Expect Symbol  NEURAL_SPAM_SHORT_PCA
diff --git a/test/functional/configs/neural.conf b/test/functional/configs/neural.conf
index 7a7f36ffc..62ff856bb 100644
--- a/test/functional/configs/neural.conf
+++ b/test/functional/configs/neural.conf
@@ -69,7 +69,7 @@ neural {
           symbol_ham = "NEURAL_HAM_SHORT_PCA";
           ann_expire = 86400;
           watch_interval = 0.5;
-          max_inputs = 2;
+          max_inputs = 10;
       }
   }
   allow_local = true;
diff --git a/test/functional/lua/neural.lua b/test/functional/lua/neural.lua
index 7ea29a252..32419c8c8 100644
--- a/test/functional/lua/neural.lua
+++ b/test/functional/lua/neural.lua
@@ -1,20 +1,23 @@
 local logger = require "rspamd_logger"
 
-rspamd_config:register_symbol({
-  name = 'SPAM_SYMBOL',
-  score = 5.0,
-  callback = function()
-    return true, 'Fires always'
-  end
-})
+for i = 1,10 do
+  rspamd_config:register_symbol({
+    name = 'SPAM_SYMBOL'..tostring(i),
+    score = 5.0,
+    callback = function()
+      return true, 'Fires always'
+    end
+  })
+  rspamd_config:register_symbol({
+    name = 'HAM_SYMBOL'..tostring(i),
+    score = -3.0,
+    callback = function()
+      return true, 'Fires always'
+    end
+  })
+end
+
 
-rspamd_config:register_symbol({
-  name = 'HAM_SYMBOL',
-  score = -3.0,
-  callback = function()
-    return true, 'Fires always'
-  end
-})
 
 rspamd_config:register_symbol({
   name = 'NEUTRAL_SYMBOL',


More information about the Commits mailing list