Skip to content

Commit

Permalink
Remove use of -1
Browse files Browse the repository at this point in the history
  • Loading branch information
kbaum committed Oct 10, 2019
1 parent 1b3efaa commit a8b2b64
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
10 changes: 5 additions & 5 deletions lib/coverband/adapters/hash_redis_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(redis, opts = {})
@redis = redis
raise 'HashRedisStore requires redis >= 2.6.0' unless supported?

@ttl = opts[:ttl] || -1
@ttl = opts[:ttl]
@relative_file_converter = opts[:relative_file_converter] || Utils::RelativeFileConverter
end

Expand Down Expand Up @@ -71,7 +71,7 @@ def save_report(report)
updated_time: updated_time
)
end
json = {
json = {
ttl: @ttl,
files_data: files_data
}.to_json
Expand Down Expand Up @@ -129,17 +129,17 @@ def script_input(key:, file:, file_hash:, data:, report_time:, updated_time:)
coverage_data = data.each_with_index.each_with_object({}) do |(coverage, index), hash|
hash[index] = coverage if coverage
end
meta = {
meta = {
first_updated_at: report_time,
file: file,
file_hash: file_hash,
file_length: data.length,
hash_key: key
}
meta.merge!(last_updated_at: updated_time) if updated_time
{
{
hash_key: key,
meta: meta ,
meta: meta,
coverage: coverage_data
}
end
Expand Down
9 changes: 3 additions & 6 deletions lua/lib/persist-coverage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ for _, file_data in ipairs(files_data) do
hmset(hash_key, file_data.meta)
redis.call('HSETNX', hash_key, 'first_updated_at', first_updated_at)
for line, coverage in pairs(file_data.coverage) do
if coverage == '-1' then
redis.call("HSET", hash_key, line, coverage)
else
redis.call("HINCRBY", hash_key, line, coverage)
end
redis.call("HINCRBY", hash_key, line, coverage)
end
if ttl > -1 then
print('ttl = ' .. inspect(ttl))
if ttl and ttl ~= cjson.null then
redis.call("EXPIRE", hash_key, ttl)
end
end
4 changes: 2 additions & 2 deletions lua/test/test-persist-coverage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("persist-coverage", function()

local key = 'hash_key'
local json = cjson.encode({
ttl = -1,
ttl = nil,
files_data = {
{
hash_key = "coverband_hash_3_3.coverband_test.runtime../dog.rb.abcd",
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("persist-coverage", function()

last_updated_at = "1569453953"
json = cjson.encode({
ttl = -1,
ttl = nil,
files_data = {
{
hash_key="coverband_hash_3_3.coverband_test.runtime../dog.rb.abcd",
Expand Down

0 comments on commit a8b2b64

Please sign in to comment.