• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blockexchange / blockexchange / 13110168475

03 Feb 2025 09:18AM UTC coverage: 48.213% (+0.6%) from 47.564%
13110168475

push

github

BuckarooBanzay
http/json overhaul

51 of 102 new or added lines in 14 files covered. (50.0%)

1 existing line in 1 file now uncovered.

985 of 2043 relevant lines covered (48.21%)

1734.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.77
/worker/load_worker.lua
1
local has_monitoring = minetest.get_modpath("monitoring")
1✔
2

3
local downloaded_blocks
4

5
if has_monitoring then
1✔
6
        downloaded_blocks = monitoring.counter(
×
7
                "blockexchange_downloaded_blocks",
8
                "number of successfully downloaded mapblocks"
9
        )
10
end
11

12
local function finalize(ctx)
13
        local msg = "Download complete with " .. ctx.total_parts .. " parts"
2✔
14
        minetest.log("action", "[blockexchange] " .. msg)
2✔
15
        if not ctx.local_load then
2✔
16
                -- fetch updated schema and register area for future updates
17
                blockexchange.register_area(ctx.pos1, ctx.pos2, ctx.playername, ctx.username, ctx.schema)
1✔
18
        end
19

20
        ctx.promise:resolve({
4✔
21
                schema = ctx.schema,
2✔
22
                last_schemapart = ctx.last_schemapart
2✔
23
        })
24
end
25

26
local function place_schemapart(schemapart, ctx)
27
        if not schemapart then
17✔
28
                finalize(ctx)
1✔
29
                return
1✔
30
        end
31

32
        -- increment stats
33
        ctx.current_part = ctx.current_part + 1
16✔
34
        ctx.progress_percent = math.floor(ctx.current_part / ctx.total_parts * 100 * 10) / 10
16✔
35

36
        local pos1 = blockexchange.place_schemapart(schemapart, ctx.origin)
16✔
37
        minetest.log("action", "[blockexchange] Download of part " .. minetest.pos_to_string(pos1) .. " completed")
32✔
38

39
        if has_monitoring then
16✔
40
                downloaded_blocks.inc(1)
×
41
        end
42

43
        ctx.last_schemapart = schemapart
16✔
44
        minetest.after(blockexchange.min_delay, blockexchange.load_worker, ctx)
16✔
45

46
        -- TODO: overwrite inworld parts if downloaded part is air-only
47
end
48

49
local function schedule_retry(ctx, err)
NEW
50
        local msg = "[blockexchange] download schemapart failed: " .. (err or "unkown") .. " retrying..."
×
UNCOV
51
        minetest.log("error", msg)
×
52

53
        -- wait a couple seconds
54
        minetest.after(5, blockexchange.load_worker, ctx)
×
55
end
56

57

58
function blockexchange.load_worker(ctx)
2✔
59
        if ctx.cancel then
18✔
60
                ctx.promise:reject("canceled")
×
61
                return
×
62
        end
63

64
        if ctx.local_load then
18✔
65
                -- local operation
66
                local current_pos = ctx.iterator()
9✔
67

68
                if not current_pos then
9✔
69
                        finalize(ctx)
1✔
70
                        return
1✔
71
                end
72

73
                local relative_pos = vector.subtract(current_pos, ctx.pos1)
8✔
74
                local filename = "schemapart_" .. relative_pos.x .. "_" .. relative_pos.y .. "_" .. relative_pos.z .. ".json"
8✔
75
                local entry = ctx.zip:get_entry(filename)
8✔
76
                if entry then
8✔
77
                        -- non-air part
78
                        local schemapart_str, err_msg = ctx.zip:get(filename, true)
8✔
79
                        if err_msg then
8✔
80
                                ctx.promise:reject("schemapart error: " .. err_msg)
×
81
                                return
×
82
                        end
83
                        local schemapart = minetest.parse_json(schemapart_str)
8✔
84
                        place_schemapart(schemapart, ctx, false)
16✔
85
                else
86
                        minetest.after(blockexchange.min_delay, blockexchange.load_worker, ctx)
×
87
                end
88

89
        elseif ctx.from_mtime > 0 then
9✔
90
                -- online, incremental download by mtime
91
                local mtime = ctx.from_mtime
×
92
                if ctx.last_schemapart then
×
93
                        -- start from last schema part
94
                        mtime = ctx.last_schemapart.mtime
×
95
                end
96
                blockexchange.api.get_next_schemapart_by_mtime(ctx.schema.uid,  mtime):next(function(schemapart)
×
97
                        place_schemapart(schemapart, ctx, false)
×
NEW
98
                end):catch(function(err)
×
NEW
99
                        schedule_retry(ctx, err)
×
100
                end)
101
        else
102
                -- online, full download
103
                if not ctx.last_schemapart then
9✔
104
                        -- start from the beginning
105
                        blockexchange.api.get_first_schemapart(ctx.schema.uid):next(function(schemapart)
3✔
106
                                place_schemapart(schemapart, ctx, false)
1✔
107
                        end):catch(function(err)
4✔
NEW
108
                                schedule_retry(ctx, err)
×
109
                        end)
110
                else
111
                        -- start from last position
112
                        local pos = {
8✔
113
                                x = ctx.last_schemapart.offset_x,
8✔
114
                                y = ctx.last_schemapart.offset_y,
8✔
115
                                z = ctx.last_schemapart.offset_z
8✔
116
                        }
117
                        blockexchange.api.get_next_schemapart(ctx.schema.uid, pos):next(function(schemapart)
24✔
118
                                place_schemapart(schemapart, ctx, false)
8✔
119
                        end):catch(function(err)
32✔
NEW
120
                                schedule_retry(ctx, err)
×
121
                        end)
122
                end
123
        end
124
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc