~gioverse/chat

0eafcb09935ce2cde1eea47b2ed6f4c2c4bec979 — Chris Waldon 2 months ago 6cb8d62
list: fix idle modification test

The idle modification test was failing because the data
inserted sorted to the end of the list while that direction
was not being ignored. This made the data get discarded.

There were two ways to fix this:

1. Ensure the Comparator hook never indicated that
the data sorted to the end of the list.
2. Trigger load requests to ensure that the async logic
realized that it was at the end of the list.

I chose to implement the first option here, though
the other should also work.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2 files changed, 12 insertions(+), 6 deletions(-)

M list/async.go
M list/async_test.go
M list/async.go => list/async.go +1 -3
@@ 41,7 41,7 @@ type stateUpdate struct {
}

func (s stateUpdate) String() string {
	return fmt.Sprintf("Synthesis: %v, Compacted: %v, Ignore: %v", s.Synthesis, s.CompactedSerials, s.Ignore)
	return fmt.Sprintf("{Synthesis: %v, Compacted: %v, Ignore: %v, Source: %v}", s.Synthesis, s.CompactedSerials, s.Ignore, s.Source)
}

// viewport represents a range of elements visible within a list.


@@ 158,8 158,6 @@ func asyncProcess(maxSize int, hooks Hooks) (chan<- interface{}, chan viewport, 
			select {
			case updateChan <- []stateUpdate{su}:
			default:
				fmt.Printf("update: %+v\n", su.Synthesis.Source)

				// Append latest update to the list.
				su := su
				pending := <-updateChan

M list/async_test.go => list/async_test.go +11 -3
@@ 315,7 315,14 @@ func updatesEqual(a, b stateUpdate) bool {
// TestCanModifyWhenIdle ensures that updates are queued if the reading
// side is idle (e.g. list manager is not currently being laid out).
func TestCanModifyWhenIdle(t *testing.T) {
	requests, viewports, updates := asyncProcess(4, testHooks)
	hooks := testHooks
	hooks.Comparator = func(i, j Element) bool {
		// For the purposes of this test, the sort order doesn't matter,
		// and we do not want to trigger the logic that filters insertions
		// at the beginning or end of the list.
		return false
	}
	requests, viewports, updates := asyncProcess(4, hooks)

	viewports <- viewport{
		Start: "0",


@@ 358,6 365,7 @@ func TestCanModifyWhenIdle(t *testing.T) {

	// We should recieve update elements 1, 2, 3, 4.
	total := 0
	var want []Element
	for pending := range updates {
		t.Log(pending)
		for ii := range pending {


@@ 367,10 375,10 @@ func TestCanModifyWhenIdle(t *testing.T) {
				t.Errorf("expected push update, got %v", su.Type)
			}
			got := su.Synthesis.Source
			want := []Element{testElement{
			want = append(want, testElement{
				serial:     strconv.Itoa(total),
				synthCount: 0,
			}}
			})
			if !reflect.DeepEqual(got, want) {
				t.Errorf("state update: want %+v, got %+v", want, got)
			}