[Tarantool-patches] [PATCH v5 5/8] box, datetime: datetime comparison for indices

Safin Timur tsafin at tarantool.org
Wed Aug 18 20:18:29 MSK 2021


On 17.08.2021 22:05, Vladimir Davydov via Tarantool-patches wrote:
> On Mon, Aug 16, 2021 at 02:59:39AM +0300, Timur Safin via
> Tarantool-patches wrote:
>> diff --git a/test/engine/datetime.test.lua
> b/test/engine/datetime.test.lua
>> new file mode 100644
>> index 000000000..3685e4d4b
>> --- /dev/null
>> +++ b/test/engine/datetime.test.lua
>> @@ -0,0 +1,35 @@
>> +env = require('test_run')
>> +test_run = env.new()
>> +engine = test_run:get_cfg('engine')
>> +
>> +date = require('datetime')
>> +
>> +_ = box.schema.space.create('T', {engine = engine})
>> +_ = box.space.T:create_index('pk', {parts={1,'datetime'}})
>> +
>> +box.space.T:insert{date('1970-01-01')}\
>> +box.space.T:insert{date('1970-01-02')}\
>> +box.space.T:insert{date('1970-01-03')}\
>> +box.space.T:insert{date('2000-01-01')}
> 
> We need more tests. Off the top of my head:
>   - unique constraint
>   - multi-part indexes
>   - index:get(key) / index:select(key)
>   - index:replace
>   - index:update / index:upsert
>   - dates before unix epoch and very big dates
>   - hint corner cases (when two different dates have the same hint)
>   - snapshot and recovery

Sigh. Could you please to show the good example for such kind of tests 
for any data types? Because I modelled my tests after uuid, and decimal, 
and I didn't see that much to be checked usually.

> 
>> +
>> +o = box.space.T:select{}
>> +assert(tostring(o[1][1]) == '1970-01-01T00:00Z')
>> +assert(tostring(o[2][1]) == '1970-01-02T00:00Z')
>> +assert(tostring(o[3][1]) == '1970-01-03T00:00Z')
>> +assert(tostring(o[4][1]) == '2000-01-01T00:00Z')
>> +
>> +for i = 1,16 do\
>> +    box.space.T:insert{date.now()}\
>> +end
> 
> Please don't use now(), because it'd make it difficult to reproduce
> a failure.
> 
>> +
>> +a = box.space.T:select{}
>> +err = {}
>> +for i = 1, #a - 1 do\
>> +    if a[i][1] >= a[i+1][1] then\
>> +        table.insert(err, {a[i][1], a[i+1][1]})\
>> +        break\
>> +    end\
>> +end
>> +
>> +err
>> +box.space.T:drop()


More information about the Tarantool-patches mailing list