fix test with snapshot interval
@@ -6,6 +6,7 @@ import filecmp
import csv
import numpy as np
import time
+import timeit
import json
import catboost
@@ -4163,7 +4164,7 @@ def test_snapshot_without_random_seed():
def test_snapshot_with_interval():
def run_with_timeout(cmd, timeout):
try:
- yatest.common.execute(cmd + additional_params, timeout=timeout)
+ yatest.common.execute(cmd, timeout=timeout)
except ExecutionTimeoutError:
return True
return False
@@ -4172,30 +4173,38 @@ def test_snapshot_with_interval():
CATBOOST_PATH,
'fit',
'--loss-function', 'Logloss',
- '--learning-rate', '0.5',
'-f', data_file('adult', 'train_small'),
'-t', data_file('adult', 'test_small'),
'--column-description', data_file('adult', 'train.cd'),
- '-i', '500',
- '-T', '4'
+ '-T', '4',
+ '-r', '0'
]
+ measure_time_iters = 100
+ exec_time = timeit.timeit(lambda: yatest.common.execute(cmd + ['-i', str(measure_time_iters)]), number=1)
+
+ SNAPSHOT_INTERVAL = 1
+ TIMEOUT = 5
+ TOTAL_TIME = 25
+ iters = int(TOTAL_TIME / (exec_time / measure_time_iters))
+
+ canon_eval_path = yatest.common.test_output_path('canon_test.eval')
+ canon_params = cmd + ['--eval-file', canon_eval_path, '-i', str(iters)]
+ yatest.common.execute(canon_params)
+
eval_path = yatest.common.test_output_path('test.eval')
progress_path = yatest.common.test_output_path('test.cbp')
model_path = yatest.common.test_output_path('model.bin')
- additional_params = ['--snapshot-file', progress_path,
- '--snapshot-interval', '1',
+ params = cmd + ['--snapshot-file', progress_path,
+ '--snapshot-interval', str(SNAPSHOT_INTERVAL),
'-m', model_path,
- '--eval-file', eval_path]
+ '--eval-file', eval_path,
+ '-i', str(iters)]
was_timeout = False
- while run_with_timeout(cmd + additional_params, 5):
+ while run_with_timeout(params, TIMEOUT):
was_timeout = True
assert was_timeout
-
- canon_eval_path = yatest.common.test_output_path('canon_test.eval')
- random_seed = catboost.CatBoost(model_file=model_path).random_seed_
- yatest.common.execute(cmd + ['-r', str(random_seed), '--eval-file', canon_eval_path])
assert filecmp.cmp(canon_eval_path, eval_path)
