From c782d38f0b4d263d243415495b8e9d9c84f119db Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 26 Feb 2021 22:14:36 -0800 Subject: 7816 --- baremetal/shell/parse.mu | 17 ++++++----------- baremetal/shell/read.mu | 6 ++++++ 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'baremetal') diff --git a/baremetal/shell/parse.mu b/baremetal/shell/parse.mu index b9eeccab..918fb108 100644 --- a/baremetal/shell/parse.mu +++ b/baremetal/shell/parse.mu @@ -1,14 +1,9 @@ fn parse-sexpression tokens: (addr stream cell), _out: (addr handle cell), trace: (addr trace) { # For now we just convert first token into a symbol and return it. TODO - var empty?/eax: boolean <- stream-empty? tokens - compare empty?, 0/false - { - break-if-!= - var out/eax: (addr handle cell) <- copy _out - allocate out - var out-addr/eax: (addr cell) <- lookup *out - read-from-stream tokens, out-addr - var type/ecx: (addr int) <- get out-addr, type - copy-to *type, 2/symbol - } + var out/eax: (addr handle cell) <- copy _out + allocate out + var out-addr/eax: (addr cell) <- lookup *out + read-from-stream tokens, out-addr + var type/ecx: (addr int) <- get out-addr, type + copy-to *type, 2/symbol } diff --git a/baremetal/shell/read.mu b/baremetal/shell/read.mu index d5a1d776..e49fbbac 100644 --- a/baremetal/shell/read.mu +++ b/baremetal/shell/read.mu @@ -3,6 +3,12 @@ fn read-cell in: (addr gap-buffer), out: (addr handle cell), trace: (addr trace) var tokens-storage: (stream cell 0x100) var tokens/ecx: (addr stream cell) <- address tokens-storage tokenize in, tokens, trace + var error?/eax: boolean <- has-errors? trace + compare error?, 0/false + { + break-if-= + return + } # TODO: insert parens # TODO: transform infix parse-sexpression tokens, out, trace -- cgit 1.4.1-2-gfad0 6bc55d91e24e70f3169ab28ce5872cf2e516220'/>
path: root/cache_test.go
blob: fc2d341c71a5e88585898269d68fb9f3db8f2357 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main

import (
	"net"
	"testing"

	"github.com/getwtxt/registry"
)

func Test_refreshCache(t *testing.T) {
	initTestConf()
	confObj.Mu.RLock()
	prevtime := confObj.LastCache
	confObj.Mu.RUnlock()

	t.Run("Cache Time Check", func(t *testing.T) {
		refreshCache()
		confObj.Mu.RLock()
		newtime := confObj.LastCache
		confObj.Mu.RUnlock()

		if !newtime.After(prevtime) || newtime == prevtime {
			t.Errorf("Cache time did not update, check refreshCache() logic\n")
		}
	})
}

func Benchmark_refreshCache(b *testing.B) {
	initTestConf()
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		refreshCache()
	}
}

func Test_pushpullDatabase(t *testing.T) {
	initTestConf()
	initDatabase()
	out, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt")
	if err != nil {
		t.Errorf("Couldn't set up test: %v\n", err)
	}
	statusmap, err := registry.ParseUserTwtxt(out, "gbmor", "https://gbmor.dev/twtxt.txt")
	if err != nil {
		t.Errorf("Couldn't set up test: %v\n", err)
	}
	twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap)
	remoteRegistries.Mu.Lock()
	remoteRegistries.List = append(remoteRegistries.List, "https://twtxt.tilde.institute/api/plain/users")
	remoteRegistries.Mu.Unlock()

	t.Run("Push to Database", func(t *testing.T) {
		err := pushDatabase()
		if err != nil {
			t.Errorf("%v\n", err)
		}
	})

	t.Run("Clearing Registry", func(t *testing.T) {
		err := twtxtCache.DelUser("https://gbmor.dev/twtxt.txt")
		if err != nil {
			t.Errorf("%v", err)
		}
	})

	t.Run("Pulling from Database", func(t *testing.T) {
		pullDatabase()
		twtxtCache.Mu.RLock()
		if _, ok := twtxtCache.Users["https://gbmor.dev/twtxt.txt"]; !ok {
			t.Errorf("Missing user previously pushed to database\n")
		}
		twtxtCache.Mu.RUnlock()

	})
}

func Benchmark_pushDatabase(b *testing.B) {
	initTestConf()

	if len(dbChan) < 1 {
		initDatabase()
	}

	if _, ok := twtxtCache.Users["https://gbmor.dev/twtxt.txt"]; !ok {
		out, _, err := registry.GetTwtxt("https://gbmor.dev/twtxt.txt")
		if err != nil {
			b.Errorf("Couldn't set up benchmark: %v\n", err)
		}

		statusmap, err := registry.ParseUserTwtxt(out, "gbmor", "https://gbmor.dev/twtxt.txt")
		if err != nil {
			b.Errorf("Couldn't set up benchmark: %v\n", err)
		}

		twtxtCache.AddUser("gbmor", "https://gbmor.dev/twtxt.txt", net.ParseIP("127.0.0.1"), statusmap)
	}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		err := pushDatabase()
		if err != nil {
			b.Errorf("%v\n", err)
		}
	}
}
func Benchmark_pullDatabase(b *testing.B) {
	initTestConf()

	if len(dbChan) < 1 {
		initDatabase()
	}

	for i := 0; i < b.N; i++ {
		pullDatabase()
	}
}