1import subprocess 2import os 3import os.path 4import sys 5from RLTest import Env 6from includes import * 7 8 9if 'EXT_TEST_PATH' in os.environ: 10 EXTPATH = os.environ['EXT_TEST_PATH'] 11else: 12 EXTPATH = 'tests/ctests/ext-example/libexample_extension.so' 13 14 15def testExt(env): 16 if env.env == 'existing-env': 17 env.skip() 18 19 if os.path.isabs(EXTPATH): 20 ext_path = EXTPATH 21 else: 22 modpath = env.module[0] 23 ext_path = os.path.abspath(os.path.join(os.path.dirname(modpath), EXTPATH)) 24 25 if not os.path.exists(ext_path): 26 raise Exception("Path ({}) does not exist. " 27 "Run from the build directory or set EXT_TEST_PATH in the environment".format(ext_path)) 28 29 env = Env(moduleArgs='EXTLOAD %s' % ext_path) 30 31 N = 100 32 env.assertOk(env.execute_command( 33 'ft.create', 'idx', 'ON', 'HASH', 'schema', 'f', 'text')) 34 for i in range(N): 35 env.assertOk(env.execute_command('ft.add', 'idx', 'doc%d' % i, 1.0, 'fields', 36 'f', 'hello world')) 37 res = env.execute_command('ft.search', 'idx', 'hello world') 38 env.assertEqual(N, res[0]) 39 res = env.execute_command('ft.search', 'idx', 'hello world', 'scorer', 'filterout_scorer') 40 env.assertEqual(0, res[0]) 41 42 if not env.isCluster(): 43 res = env.cmd('ft.config', 'get', 'EXTLOAD')[0][1] 44 env.assertContains('libexample_extension', res) 45