feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune
ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v), q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)). ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no longer uses, nor anything it calls, and the argument that fills it - including an argument for a parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8cf4b3fed6
commit
71735b10a2
151 changed files with 58668 additions and 54719 deletions
|
|
@ -10,7 +10,7 @@ export function telemetry_random_hex(telemetry_st: mut TelemetryState, n: int) -
|
|||
}
|
||||
|
||||
# the id outright (a game with accounts of its own, a test); written to the id file
|
||||
export function telemetry_set_id(base_st: mut BaseState, telemetry_st: mut TelemetryState, id: string) -> void {
|
||||
export function telemetry_set_id(telemetry_st: mut TelemetryState, id: string) -> void {
|
||||
telemetry_st.telemetry__id = id
|
||||
let path = telemetry__conf(telemetry_st).id_file
|
||||
if len(path) > 0 {
|
||||
|
|
@ -19,25 +19,25 @@ export function telemetry_set_id(base_st: mut BaseState, telemetry_st: mut Telem
|
|||
Value.put(v, "id", Value.str(id))
|
||||
Fs.write_text(path, Json.encode(v))
|
||||
}
|
||||
telemetry__fact(base_st, telemetry_st, TELEMETRY_ID, 0, 0, 0)
|
||||
telemetry__fact(telemetry_st, TELEMETRY_ID, 0, 0, 0)
|
||||
}
|
||||
|
||||
function telemetry__random_id(base_st: mut BaseState, telemetry_st: mut TelemetryState) -> void { telemetry_set_id(base_st, telemetry_st, "r-" + telemetry_random_hex(telemetry_st, 16)) }
|
||||
function telemetry__random_id(telemetry_st: mut TelemetryState) -> void { telemetry_set_id(telemetry_st, "r-" + telemetry_random_hex(telemetry_st, 16)) }
|
||||
|
||||
function telemetry__from_machine(base_st: mut BaseState, telemetry_st: mut TelemetryState, raw: string) -> void {
|
||||
function telemetry__from_machine(telemetry_st: mut TelemetryState, raw: string) -> void {
|
||||
let salt = telemetry__conf(telemetry_st).id_salt
|
||||
telemetry_set_id(base_st, telemetry_st, "m-" + Crypto.sha256(salt + ":" + Text.lower(raw))[0..32])
|
||||
telemetry_set_id(telemetry_st, "m-" + Crypto.sha256(salt + ":" + Text.lower(raw))[0..32])
|
||||
}
|
||||
|
||||
function telemetry__id_begin(base_st: mut BaseState, telemetry_st: mut TelemetryState) -> void {
|
||||
function telemetry__id_begin(telemetry_st: mut TelemetryState) -> void {
|
||||
if len(telemetry__conf(telemetry_st).id_salt) == 0 {
|
||||
telemetry__random_id(base_st, telemetry_st)
|
||||
telemetry__random_id(telemetry_st)
|
||||
return
|
||||
}
|
||||
let plat = Os.platform()
|
||||
if plat == "linux" {
|
||||
let m = Fs.read_text("/etc/machine-id")
|
||||
if m != null and len(Text.trim(m)) > 0 { telemetry__from_machine(base_st, telemetry_st, Text.trim(m)) } else { telemetry__random_id(base_st, telemetry_st) }
|
||||
if m != null and len(Text.trim(m)) > 0 { telemetry__from_machine(telemetry_st, Text.trim(m)) } else { telemetry__random_id(telemetry_st) }
|
||||
return
|
||||
}
|
||||
telemetry_st.telemetry__proc_out = telemetry__conf(telemetry_st).id_scratch
|
||||
|
|
@ -45,7 +45,7 @@ function telemetry__id_begin(base_st: mut BaseState, telemetry_st: mut Telemetry
|
|||
if Fs.exists(telemetry_st.telemetry__proc_out) { Fs.remove(telemetry_st.telemetry__proc_out) }
|
||||
telemetry_st.telemetry__proc = telemetry__spawn_machine(telemetry_st, plat)
|
||||
telemetry_st.telemetry__proc_t0 = Time.now()
|
||||
if telemetry_st.telemetry__proc < 0 { telemetry__random_id(base_st, telemetry_st) }
|
||||
if telemetry_st.telemetry__proc < 0 { telemetry__random_id(telemetry_st) }
|
||||
}
|
||||
|
||||
function telemetry__spawn_machine(telemetry_st: TelemetryState, plat: string) -> int {
|
||||
|
|
@ -66,7 +66,7 @@ function telemetry__spawn_machine(telemetry_st: TelemetryState, plat: string) ->
|
|||
}
|
||||
|
||||
# the machine id, once the child has written it (ten seconds at most)
|
||||
function telemetry__id_tick(base_st: mut BaseState, telemetry_st: mut TelemetryState) -> void {
|
||||
function telemetry__id_tick(telemetry_st: mut TelemetryState) -> void {
|
||||
if telemetry_st.telemetry__proc < 0 { return }
|
||||
let code = Process.poll(telemetry_st.telemetry__proc)
|
||||
if code < 0 {
|
||||
|
|
@ -74,7 +74,7 @@ function telemetry__id_tick(base_st: mut BaseState, telemetry_st: mut TelemetryS
|
|||
Process.kill(telemetry_st.telemetry__proc)
|
||||
Process.free(telemetry_st.telemetry__proc)
|
||||
telemetry_st.telemetry__proc = -1
|
||||
telemetry__random_id(base_st, telemetry_st)
|
||||
telemetry__random_id(telemetry_st)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -84,5 +84,5 @@ function telemetry__id_tick(base_st: mut BaseState, telemetry_st: mut TelemetryS
|
|||
let s = Fs.read_text(telemetry_st.telemetry__proc_out)
|
||||
if s != null { raw = Text.trim(s) }
|
||||
if Fs.exists(telemetry_st.telemetry__proc_out) { Fs.remove(telemetry_st.telemetry__proc_out) }
|
||||
if code == 0 and len(raw) >= 8 { telemetry__from_machine(base_st, telemetry_st, raw) } else { telemetry__random_id(base_st, telemetry_st) }
|
||||
if code == 0 and len(raw) >= 8 { telemetry__from_machine(telemetry_st, raw) } else { telemetry__random_id(telemetry_st) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export function telemetry_queued(telemetry_st: TelemetryState) -> int {
|
|||
export function telemetry_line(telemetry_st: TelemetryState, i: int) -> string { return telemetry_st.telemetry__q[i] }
|
||||
|
||||
# back to before telemetry_start, ports and config kept (tests; a start after a failed boot)
|
||||
export function telemetry_reset(base_st: mut BaseState, telemetry_st: mut TelemetryState) -> void {
|
||||
export function telemetry_reset(telemetry_st: mut TelemetryState) -> void {
|
||||
telemetry__drop_request(telemetry_st)
|
||||
telemetry_st.telemetry__ready = false
|
||||
telemetry_st.telemetry__id = ""
|
||||
|
|
@ -29,5 +29,5 @@ export function telemetry_reset(base_st: mut BaseState, telemetry_st: mut Teleme
|
|||
telemetry_st.telemetry__fails = 0
|
||||
telemetry_st.telemetry__clock_on = false
|
||||
telemetry_st.telemetry__proc = -1
|
||||
q_clear(base_st, telemetry_facts(base_st, telemetry_st))
|
||||
q_clear(telemetry_facts(telemetry_st))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
# queue.ludic - a start, an event encoded once into a line, the queue on disk, and forgetting
|
||||
# once, at boot: who this is (from the id file, or begun from the machine), a new session, and
|
||||
# whatever an earlier start left unsent - or nothing, if the player has it off
|
||||
export function telemetry_start(base_st: mut BaseState, telemetry_st: mut TelemetryState) -> void {
|
||||
export function telemetry_start(telemetry_st: mut TelemetryState) -> void {
|
||||
if telemetry_st.telemetry__ready { return }
|
||||
telemetry_st.telemetry__ready = true
|
||||
telemetry_st.telemetry__t0 = Time.now()
|
||||
telemetry_st.telemetry__session = telemetry_random_hex(telemetry_st, 16)
|
||||
telemetry_st.telemetry__q = new []string
|
||||
telemetry_st.telemetry__id = sv_str(telemetry__read_obj(telemetry__conf(telemetry_st).id_file), "id", "")
|
||||
if len(telemetry_st.telemetry__id) == 0 { telemetry__id_begin(base_st, telemetry_st) }
|
||||
if len(telemetry_st.telemetry__id) == 0 { telemetry__id_begin(telemetry_st) }
|
||||
if telemetry__enabled() { telemetry__queue_load(telemetry_st) } else { telemetry_forget(telemetry_st) }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
# send.ludic - every frame: a batch when one is due, its answer when it lands, the wait doubled
|
||||
# when it failed, the queue on disk every few seconds. One request at a time; nothing waits on it.
|
||||
|
||||
export function telemetry_tick(base_st: mut BaseState, telemetry_st: mut TelemetryState) -> void {
|
||||
export function telemetry_tick(telemetry_st: mut TelemetryState) -> void {
|
||||
if not telemetry_st.telemetry__ready { return }
|
||||
telemetry__id_tick(base_st, telemetry_st)
|
||||
telemetry__id_tick(telemetry_st)
|
||||
if not telemetry__enabled() {
|
||||
if len(telemetry_st.telemetry__q) > 0 or telemetry_st.telemetry__h >= 0 { telemetry_forget(telemetry_st) }
|
||||
return
|
||||
|
|
@ -21,19 +21,19 @@ export function telemetry_tick(base_st: mut BaseState, telemetry_st: mut Telemet
|
|||
telemetry_st.telemetry__saved_ms = now
|
||||
}
|
||||
if telemetry_st.telemetry__h >= 0 {
|
||||
telemetry__answer(base_st, telemetry_st, now)
|
||||
telemetry__answer(telemetry_st, now)
|
||||
return
|
||||
}
|
||||
if len(telemetry_st.telemetry__q) == 0 { return }
|
||||
let early = telemetry_st.telemetry__fails == 0 and len(telemetry_st.telemetry__q) >= c.flush_at
|
||||
if early or now >= telemetry_st.telemetry__next_ms {
|
||||
telemetry_save(telemetry_st)
|
||||
telemetry__flush(base_st, telemetry_st, now)
|
||||
telemetry__flush(telemetry_st, now)
|
||||
if telemetry_st.telemetry__fails == 0 { telemetry_st.telemetry__next_ms = now + c.flush_ms }
|
||||
}
|
||||
}
|
||||
|
||||
function telemetry__answer(base_st: mut BaseState, telemetry_st: mut TelemetryState, now: int) -> void {
|
||||
function telemetry__answer(telemetry_st: mut TelemetryState, now: int) -> void {
|
||||
let st = telemetry__poll(telemetry_st.telemetry__h)
|
||||
if st < 0 { return }
|
||||
telemetry_st.telemetry__h = -1
|
||||
|
|
@ -41,21 +41,21 @@ function telemetry__answer(base_st: mut BaseState, telemetry_st: mut TelemetrySt
|
|||
telemetry__queue_drop(telemetry_st, telemetry_st.telemetry__sent_n)
|
||||
telemetry_st.telemetry__fails = 0
|
||||
telemetry_st.telemetry__next_ms = now + telemetry__conf(telemetry_st).flush_ms
|
||||
telemetry__fact(base_st, telemetry_st, TELEMETRY_SENT, telemetry_st.telemetry__sent_n, st, 0)
|
||||
telemetry__fact(telemetry_st, TELEMETRY_SENT, telemetry_st.telemetry__sent_n, st, 0)
|
||||
} else {
|
||||
telemetry__backoff(telemetry_st, now)
|
||||
telemetry__fact(base_st, telemetry_st, TELEMETRY_FAILED, telemetry_st.telemetry__sent_n, st, telemetry_st.telemetry__next_ms - now)
|
||||
telemetry__fact(telemetry_st, TELEMETRY_FAILED, telemetry_st.telemetry__sent_n, st, telemetry_st.telemetry__next_ms - now)
|
||||
}
|
||||
telemetry_save(telemetry_st)
|
||||
}
|
||||
|
||||
function telemetry__flush(base_st: mut BaseState, telemetry_st: mut TelemetryState, now: int) -> void {
|
||||
function telemetry__flush(telemetry_st: mut TelemetryState, now: int) -> void {
|
||||
if telemetry_st.telemetry__h >= 0 or len(telemetry_st.telemetry__id) == 0 or len(telemetry_st.telemetry__q) == 0 { return }
|
||||
let n = min(telemetry__conf(telemetry_st).batch, len(telemetry_st.telemetry__q))
|
||||
let h = telemetry__send(telemetry_st, telemetry_batch_body(telemetry_st, n))
|
||||
if h < 0 {
|
||||
telemetry__backoff(telemetry_st, now)
|
||||
telemetry__fact(base_st, telemetry_st, TELEMETRY_FAILED, n, 0, telemetry_st.telemetry__next_ms - now)
|
||||
telemetry__fact(telemetry_st, TELEMETRY_FAILED, n, 0, telemetry_st.telemetry__next_ms - now)
|
||||
return
|
||||
}
|
||||
telemetry_st.telemetry__h = h
|
||||
|
|
|
|||
|
|
@ -67,16 +67,16 @@ export state TelemetryState {
|
|||
telemetry__facts: Queue<TelemetryFact> = null
|
||||
}
|
||||
|
||||
export function telemetry_facts(base_st: mut BaseState, telemetry_st: mut TelemetryState) -> Queue<TelemetryFact> {
|
||||
if telemetry_st.telemetry__facts == null { telemetry_st.telemetry__facts = queue_new(base_st, "telemetry.facts") }
|
||||
export function telemetry_facts(telemetry_st: mut TelemetryState) -> Queue<TelemetryFact> {
|
||||
if telemetry_st.telemetry__facts == null { telemetry_st.telemetry__facts = queue_new("telemetry.facts") }
|
||||
return telemetry_st.telemetry__facts
|
||||
}
|
||||
|
||||
function telemetry__fact(base_st: mut BaseState, telemetry_st: mut TelemetryState, what: int, count: int, status: int, retry: int) -> void {
|
||||
function telemetry__fact(telemetry_st: mut TelemetryState, what: int, count: int, status: int, retry: int) -> void {
|
||||
let f = new TelemetryFact
|
||||
f.what = what
|
||||
f.count = count
|
||||
f.status = status
|
||||
f.retry_ms = retry
|
||||
q_push(base_st, telemetry_facts(base_st, telemetry_st), f)
|
||||
q_push(telemetry_facts(telemetry_st), f)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ program TelemetryTest {
|
|||
function qfile() -> string { return Os.temp_dir() + "/ludic-telemetry-test-queue.txt" }
|
||||
function idfile() -> string { return Os.temp_dir() + "/ludic-telemetry-test-id.json" }
|
||||
|
||||
function fresh(base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) -> void {
|
||||
function fresh(telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) -> void {
|
||||
telemetry_test_st.clock = 0
|
||||
telemetry_test_st.on = true
|
||||
telemetry_test_st.allowed = true
|
||||
|
|
@ -44,7 +44,7 @@ program TelemetryTest {
|
|||
telemetry_test_st.sends = 0
|
||||
telemetry_test_st.last_url = ""
|
||||
telemetry_test_st.last_body = ""
|
||||
telemetry_reset(base_st, telemetry_st)
|
||||
telemetry_reset(telemetry_st)
|
||||
if Fs.exists(qfile()) { Fs.remove(qfile()) }
|
||||
Fs.write_text(idfile(), "{\"id\":\"p-1\",\"notices\":2}")
|
||||
let c = new TelemetryConfig
|
||||
|
|
@ -60,28 +60,28 @@ program TelemetryTest {
|
|||
c.backoff_max = 2
|
||||
c.save_ms = 100000
|
||||
telemetry_config(telemetry_st, c)
|
||||
telemetry_start(base_st, telemetry_st)
|
||||
telemetry_tick(base_st, telemetry_st)
|
||||
telemetry_start(telemetry_st)
|
||||
telemetry_tick(telemetry_st)
|
||||
}
|
||||
|
||||
function events(telemetry_st: mut TelemetryState, n: int) -> void {
|
||||
for i in 0 .. n { telemetry_event(telemetry_st, `e{i}`, null) }
|
||||
}
|
||||
|
||||
function at(base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState, ms: int) -> void {
|
||||
function at(telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState, ms: int) -> void {
|
||||
telemetry_test_st.clock = ms
|
||||
telemetry_tick(base_st, telemetry_st)
|
||||
telemetry_tick(telemetry_st)
|
||||
}
|
||||
|
||||
function facts_of(base_st: mut BaseState, telemetry_st: mut TelemetryState, what: int) -> int {
|
||||
let fs = q_drain(base_st, telemetry_facts(base_st, telemetry_st))
|
||||
function facts_of(telemetry_st: mut TelemetryState, what: int) -> int {
|
||||
let fs = q_drain(telemetry_facts(telemetry_st))
|
||||
var n = 0
|
||||
for i in 0 .. len(fs) { if fs[i].what == what { n += 1 } }
|
||||
return n
|
||||
}
|
||||
|
||||
test "an event is one line with the player as a mark, and the batch puts the id in" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "an event is one line with the player as a mark, and the batch puts the id in" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
expect(telemetry_id(telemetry_st) == "p-1")
|
||||
telemetry_event(telemetry_st, "hello", null)
|
||||
expect_eq(telemetry_queued(telemetry_st), 1)
|
||||
|
|
@ -94,108 +94,108 @@ program TelemetryTest {
|
|||
expect(Text.contains(body, "\"distinct_id\":\"p-1\""))
|
||||
}
|
||||
|
||||
test "a batch goes when due, and only what the server took leaves the queue" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "a batch goes when due, and only what the server took leaves the queue" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
events(telemetry_st, 4)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 500)
|
||||
at(telemetry_st, telemetry_test_st, 500)
|
||||
expect_eq(telemetry_test_st.sends, 0)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 1000)
|
||||
at(telemetry_st, telemetry_test_st, 1000)
|
||||
expect_eq(telemetry_test_st.sends, 1)
|
||||
expect(telemetry_test_st.last_url == "http://fake/batch/")
|
||||
expect(telemetry_in_flight(telemetry_st))
|
||||
events(telemetry_st, 1)
|
||||
telemetry_test_st.answer = 1
|
||||
at(base_st, telemetry_st, telemetry_test_st, 1100)
|
||||
at(telemetry_st, telemetry_test_st, 1100)
|
||||
expect_eq(telemetry_queued(telemetry_st), 2)
|
||||
expect_eq(facts_of(base_st, telemetry_st, TELEMETRY_SENT), 1)
|
||||
expect_eq(facts_of(telemetry_st, TELEMETRY_SENT), 1)
|
||||
}
|
||||
|
||||
test "enough events go early" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "enough events go early" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
events(telemetry_st, 5)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 10)
|
||||
at(telemetry_st, telemetry_test_st, 10)
|
||||
expect_eq(telemetry_test_st.sends, 1)
|
||||
}
|
||||
|
||||
test "a failure keeps the lines and waits twice as long, up to the cap" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "a failure keeps the lines and waits twice as long, up to the cap" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
events(telemetry_st, 2)
|
||||
telemetry_test_st.answer = 0
|
||||
at(base_st, telemetry_st, telemetry_test_st, 1000)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 1001)
|
||||
at(telemetry_st, telemetry_test_st, 1000)
|
||||
at(telemetry_st, telemetry_test_st, 1001)
|
||||
expect_eq(telemetry_queued(telemetry_st), 2)
|
||||
expect_eq(telemetry_fails(telemetry_st), 1)
|
||||
expect_eq(telemetry_next_ms(telemetry_st), 1001 + 2000)
|
||||
expect_eq(facts_of(base_st, telemetry_st, TELEMETRY_FAILED), 1)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 3001)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 3002)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 7002)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 7003)
|
||||
expect_eq(facts_of(telemetry_st, TELEMETRY_FAILED), 1)
|
||||
at(telemetry_st, telemetry_test_st, 3001)
|
||||
at(telemetry_st, telemetry_test_st, 3002)
|
||||
at(telemetry_st, telemetry_test_st, 7002)
|
||||
at(telemetry_st, telemetry_test_st, 7003)
|
||||
expect_eq(telemetry_fails(telemetry_st), 2)
|
||||
expect_eq(telemetry_next_ms(telemetry_st), 7003 + 4000)
|
||||
}
|
||||
|
||||
test "a request that cannot start backs off too" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "a request that cannot start backs off too" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
telemetry_test_st.refuse = true
|
||||
events(telemetry_st, 1)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 1000)
|
||||
at(telemetry_st, telemetry_test_st, 1000)
|
||||
expect_eq(telemetry_fails(telemetry_st), 1)
|
||||
expect(not telemetry_in_flight(telemetry_st))
|
||||
}
|
||||
|
||||
test "off keeps nothing and deletes the file" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "off keeps nothing and deletes the file" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
events(telemetry_st, 3)
|
||||
telemetry_save(telemetry_st)
|
||||
expect(Fs.exists(qfile()))
|
||||
telemetry_test_st.on = false
|
||||
at(base_st, telemetry_st, telemetry_test_st, 10)
|
||||
at(telemetry_st, telemetry_test_st, 10)
|
||||
expect_eq(telemetry_queued(telemetry_st), 0)
|
||||
expect(not Fs.exists(qfile()))
|
||||
events(telemetry_st, 3)
|
||||
expect_eq(telemetry_queued(telemetry_st), 0)
|
||||
}
|
||||
|
||||
test "a run that may not send queues nothing and sends nothing" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "a run that may not send queues nothing and sends nothing" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
telemetry_test_st.allowed = false
|
||||
events(telemetry_st, 9)
|
||||
at(base_st, telemetry_st, telemetry_test_st, 100000)
|
||||
at(telemetry_st, telemetry_test_st, 100000)
|
||||
expect_eq(telemetry_queued(telemetry_st), 0)
|
||||
expect_eq(telemetry_test_st.sends, 0)
|
||||
}
|
||||
|
||||
test "the queue is capped at its newest events" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "the queue is capped at its newest events" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
telemetry_test_st.allowed = true
|
||||
events(telemetry_st, 12)
|
||||
expect(telemetry_queued(telemetry_st) <= 11)
|
||||
expect(Text.contains(telemetry_line(telemetry_st, telemetry_queued(telemetry_st) - 1), "e11"))
|
||||
}
|
||||
|
||||
test "what was not sent is there at the next start" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
test "what was not sent is there at the next start" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
events(telemetry_st, 3)
|
||||
telemetry_save(telemetry_st)
|
||||
telemetry_reset(base_st, telemetry_st)
|
||||
telemetry_start(base_st, telemetry_st)
|
||||
telemetry_reset(telemetry_st)
|
||||
telemetry_start(telemetry_st)
|
||||
expect_eq(telemetry_queued(telemetry_st), 3)
|
||||
}
|
||||
|
||||
test "an id set outright is written beside the file's other keys" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
telemetry_set_id(base_st, telemetry_st, "p-2")
|
||||
test "an id set outright is written beside the file's other keys" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
telemetry_set_id(telemetry_st, "p-2")
|
||||
let v = Json.parse(Fs.read_text(idfile()))
|
||||
expect(sv_str(v, "id", "") == "p-2")
|
||||
expect_eq(sv_int(v, "notices", 0), 2)
|
||||
}
|
||||
|
||||
test "no salt and no id file makes a random id" (base_st: mut BaseState, telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(base_st, telemetry_st, telemetry_test_st)
|
||||
telemetry_reset(base_st, telemetry_st)
|
||||
test "no salt and no id file makes a random id" (telemetry_st: mut TelemetryState, telemetry_test_st: mut TelemetryTestState) {
|
||||
fresh(telemetry_st, telemetry_test_st)
|
||||
telemetry_reset(telemetry_st)
|
||||
Fs.remove(idfile())
|
||||
telemetry_start(base_st, telemetry_st)
|
||||
telemetry_start(telemetry_st)
|
||||
expect(Text.starts_with(telemetry_id(telemetry_st), "r-"))
|
||||
expect_eq(len(telemetry_session(telemetry_st)), 32)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue