Explorar el Código

Closed a timing bug

arianagiroux hace 1 semana
padre
commit
b03020d85e

+ 6 - 5
cmd/pingo.go

@@ -19,6 +19,7 @@ import (
 
 type md struct {
 	viewport viewport.Model
+	speed    time.Duration
 	p        pingo.Model
 }
 
@@ -39,7 +40,7 @@ var (
 )
 
 func (m md) Init() tea.Cmd {
-	return tea.Tick(100*time.Millisecond, func(t time.Time) tea.Msg { return timingMsg(t) })
+	return tea.Tick(m.speed*time.Millisecond, func(t time.Time) tea.Msg { return timingMsg(t) })
 }
 
 func (m md) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@@ -65,8 +66,8 @@ func (m md) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			return m, tea.Quit
 		}
 	case timingMsg:
-		cmd = tea.Tick(100*time.Millisecond, func(t time.Time) tea.Msg { return timingMsg(t) })
-		cmds = append(cmds, cmd, m.p.Poll())
+		cmd = tea.Tick(m.speed*time.Millisecond, func(t time.Time) tea.Msg { return timingMsg(t) })
+		cmds = append(cmds, tea.Sequence(m.p.Poll(), cmd))
 	}
 
 	m.viewport.SetContent(m.p.View().Content)
@@ -99,7 +100,7 @@ func (m md) footer() string {
 func (m md) getVerticalMargin() int { return lipgloss.Height(m.header() + m.footer()) }
 
 func main() {
-	// speed := flag.Int("s", 80, "the speed with which the UI runs")
+	speed := flag.Int("s", 80, "the speed with which the UI runs")
 	chartHeight := flag.Int("h", 0,
 		"the height of the latency chart. set to 0 to render charts full screen.")
 	flag.Parse()
@@ -110,7 +111,7 @@ func main() {
 		return
 	}
 
-	p := tea.NewProgram(md{p: pingo.InitialModel(hosts, 20, 10, *chartHeight)})
+	p := tea.NewProgram(md{p: pingo.InitialModel(hosts, 20, 10, *chartHeight), speed: time.Duration(*speed)})
 
 	if _, err := p.Run(); err != nil {
 		fmt.Printf("Alas, there's been an error: %v", err)

+ 9 - 10
cmd/pingo_test.go

@@ -4,7 +4,6 @@ import (
 	"pingo"
 	"strings"
 	"testing"
-	"time"
 
 	tea "charm.land/bubbletea/v2"
 	"charm.land/lipgloss/v2"
@@ -49,16 +48,16 @@ func Test_md_Update_handle_keymsg(t *testing.T) {
 func Test_md_Update_handle_timing(t *testing.T) {
 	testMD := spawnMD([]string{"127.0.0.1"}, 40, 20, 10)
 	_, cmd := testMD.Update(tea.Msg(timingMsg{}))
-	assert.NotNil(t, cmd)
-	assert.IsType(t, *new(tea.BatchMsg), cmd())
+	assert.NotNil(t, cmd())
+	// assert.IsType(t, *new(tea.BatchMsg), cmd())
 
-	batch := []tea.Cmd(cmd().(tea.BatchMsg))
-	assert.True(t, len(batch) == 2)
-	for _, cmd := range batch {
-		if value, ok := cmd().(timingMsg); ok {
-			assert.WithinDuration(t, time.Now(), time.Time(value), time.Second*1)
-		}
-	}
+	// batch := []tea.Cmd(cmd().(tea.BatchMsg))
+	// assert.True(t, len(batch) == 2)
+	// for _, cmd := range batch {
+	// 	if value, ok := cmd().(timingMsg); ok {
+	// 		assert.WithinDuration(t, time.Now(), time.Time(value), time.Second*1)
+	// 	}
+	// }
 }
 
 func Test_md_View(t *testing.T) {

+ 0 - 6
issues/bug:-Model.Poll-can-overwrite-itself/description

@@ -1,6 +0,0 @@
-Poll() architecture can result in result lists being overwritten
-
----
-Poll() needs a method to ensure that a new set of pings go out only when the previous ping to the relevant address is done. This can be reproduced by polling an address with a varied/incosistent delay times.
-
-Effectively, if a result comes in *after* a subsequent ping, it will drop the history tracked internally.

+ 0 - 1
issues/bug:-Model.Poll-can-overwrite-itself/status

@@ -1 +0,0 @@
-open

+ 0 - 0
issues/bug:-Model.Poll-can-overwrite-itself/tags/bug


+ 0 - 0
issues/bug:-Model.Poll-can-overwrite-itself/tags/fatal


+ 0 - 0
issues/bug:-Model.Poll-can-overwrite-itself/tags/v0.1