Ariver
2026-06-29 084cdd26d0f2bfa96d165c0a77a0697406919634
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package services
 
import "testing"
 
func TestEngineServiceDownloadStatusTracksCancelAndFinish(t *testing.T) {
    service := NewEngineService(nil)
    status := service.GetModelDownloadStatus()
    if status["active"].(bool) {
        t.Fatal("new service should not report an active model download")
    }
 
    _, finish, err := service.beginModelDownload("zipformer-ko")
    if err != nil {
        t.Fatal(err)
    }
    status = service.GetModelDownloadStatus()
    if !status["active"].(bool) {
        t.Fatal("active download was not reported")
    }
    if got := status["modelID"]; got != "zipformer-ko" {
        t.Fatalf("modelID = %v, want zipformer-ko", got)
    }
    if status["cancelling"].(bool) {
        t.Fatal("new download should not start in cancelling state")
    }
 
    service.updateModelDownloadProgress("zipformer-ko", 42.5, 425, 1000)
    status = service.GetModelDownloadStatus()
    if got := status["percent"]; got != 42.5 {
        t.Fatalf("percent = %v, want 42.5", got)
    }
    if got := status["downloaded"]; got != int64(425) {
        t.Fatalf("downloaded = %v, want 425", got)
    }
    if got := status["total"]; got != int64(1000) {
        t.Fatalf("total = %v, want 1000", got)
    }
 
    if !service.CancelModelDownload("zipformer-ko") {
        t.Fatal("expected active download to be cancelled")
    }
    status = service.GetModelDownloadStatus()
    if !status["cancelling"].(bool) {
        t.Fatal("cancelled download should report cancelling state until finish")
    }
 
    finish()
    status = service.GetModelDownloadStatus()
    if status["active"].(bool) {
        t.Fatal("finished download should clear active state")
    }
    if got := status["modelID"]; got != "" {
        t.Fatalf("modelID after finish = %v, want empty", got)
    }
}