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

razor-network / oracle-node / 10882594019

16 Sep 2024 05:47AM UTC coverage: 80.604% (+0.1%) from 80.5%
10882594019

push

github

web-flow
Releases/v1.2.0 (#1236)

* chore: merge develop to releases/v1.2.0 (#1227)

* feat: Github Migration  (#1146)

* feat: migrate to github actions

* chore: migrate from circle ci

* Update develop.yml (#1148)

* Update develop.yml (#1149)

* Update develop.yml

* Update develop.yml

* Update develop.yml

* Fix go mod tidy

* Replaced curve instance elliptic.P256() with crypto.S256() (#1150)

* fix: Update Dockerfile with version bumps (#1152)

* chore: hotfix missing workflow

* chore: fix dockerfile versions

* Feature/v1.1.0 (#1154)

* v1.2.0 (#965)

* Hotfix-logImprovements (#952)

* Set up blocknumber and epoch in logs

* updated blocknumber and epoch logger info in every command

* Hotfix-getDataFromAPI (#951)

* Changed numm of retry attempts

* removed redundant retry attempts

* corrected tests

* changed http timeout and logged time elapsed to fetch data (#954)

* Updated version (#960)

* Updated version

* updated version to v1.2.0

* version update (#972)

* Merged `v1.3.0-alpha` into `v1.0.5` (#973)

* Merged `v1` into `v1.3.0-aplha` with hotfixes (#966)

* Hotfix-proposed data (#913)

* Updated propose data global variables correctly

* Fixed tests

* Returned correct waitForBlockCompletion error

* coverage increase

* GetLocalData returns type types.ProposeFileData

* fixed benchmark

* Fetched Last proposed from contracts (#917)

* fetched getLastProposedEpoch from contracts and tests for it

* typo fix

* V1 propose hotfix (#918)

* Change propose.go to get sorted proposed block ids.
* Fix sorted proposed block issue.

Signed-off-by: Ashish Kumar Mishra <ashish10677@gmail.com>

* allow stakers to addStake < minSafeRazor (#928)

* Call claimStakerReward only if there reward to claim (#926)

* Make contract call only if there is commission to claim

* Add tests for claimCommission file

* update check

* Hotfix-giveSorted (#921)

* ResetDi... (continued)

887 of 1091 new or added lines in 40 files covered. (81.3%)

22 existing lines in 6 files now uncovered.

6641 of 8239 relevant lines covered (80.6%)

2524.53 hits per line

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

93.88
/cache/cache.go
1
package cache
2

3
import (
4
        "sync"
5
        "time"
6
)
7

8
type cachedData struct {
9
        Result            []byte
10
        expireAtTimestamp int64
11
}
12

13
type LocalCache struct {
14
        stop chan struct{}
15

16
        wg   sync.WaitGroup
17
        mu   sync.RWMutex
18
        URLs map[string]cachedData //URLs
19
}
20

21
func NewLocalCache(cleanupInterval time.Duration) *LocalCache {
31✔
22
        lc := &LocalCache{
31✔
23
                URLs: make(map[string]cachedData),
31✔
24
                stop: make(chan struct{}),
31✔
25
        }
31✔
26

31✔
27
        lc.wg.Add(1)
31✔
28
        go func(cleanupInterval time.Duration) {
62✔
29
                defer lc.wg.Done()
31✔
30
                lc.cleanupLoop(cleanupInterval)
31✔
31
        }(cleanupInterval)
31✔
32

33
        return lc
31✔
34
}
35

36
func (lc *LocalCache) cleanupLoop(interval time.Duration) {
31✔
37
        t := time.NewTicker(interval)
31✔
38
        defer t.Stop()
31✔
39

31✔
40
        for {
170✔
41
                select {
139✔
42
                case <-lc.stop:
4✔
43
                        return
4✔
44
                case <-t.C:
108✔
45
                        lc.mu.Lock()
108✔
46
                        for url, cu := range lc.URLs {
211✔
47
                                if cu.expireAtTimestamp <= time.Now().Unix() {
103✔
48
                                        delete(lc.URLs, url)
×
49
                                }
×
50
                        }
51
                        lc.mu.Unlock()
108✔
52
                }
53
        }
54
}
55

56
func (lc *LocalCache) StopCleanup() {
4✔
57
        close(lc.stop)
4✔
58
        lc.wg.Wait()
4✔
59
}
4✔
60

61
func (lc *LocalCache) Update(data []byte, url string, expireAtTimestamp int64) {
23✔
62
        lc.mu.Lock()
23✔
63
        defer lc.mu.Unlock()
23✔
64

23✔
65
        lc.URLs[url] = cachedData{
23✔
66
                Result:            data,
23✔
67
                expireAtTimestamp: expireAtTimestamp,
23✔
68
        }
23✔
69
}
23✔
70

71
// Read fetches cached data for the given URL and indicates its presence with a boolean.
72
func (lc *LocalCache) Read(url string) ([]byte, bool) {
29✔
73
        lc.mu.RLock()
29✔
74
        defer lc.mu.RUnlock()
29✔
75

29✔
76
        cacheData, ok := lc.URLs[url]
29✔
77
        if !ok {
58✔
78
                return nil, false // Data not found, return nil and false
29✔
79
        }
29✔
80

UNCOV
81
        return cacheData.Result, true
×
82
}
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