MCPcopy Create free account
hub / github.com/rilldata/rill / TestWatch

Function TestWatch

runtime/controller_test.go:1123–1194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1121}
1122
1123func TestWatch(t *testing.T) {
1124 // Create instance with watch
1125 // Create source, wait and verify
1126 // Create model, wait and verify
1127 // Create metrics view, wait and verify
1128 // Drop source, wait and verify
1129
1130 rt, id := testruntime.NewInstanceWithOptions(t, testruntime.InstanceOptions{
1131 Files: map[string]string{"rill.yaml": ""},
1132 WatchRepo: true,
1133 })
1134
1135 ctrl, err := rt.Controller(context.Background(), id)
1136 require.NoError(t, err)
1137
1138 // Since we're using WatchRepo, we can't use testruntime.ReconcileParserAndWait.
1139 // For now, we'll just add a sleep to give the file watcher time to trigger.
1140 // NOTE: Refactor to wait for the controller to actually be triggered if we ever have instability
1141 awaitIdle := func() {
1142 time.Sleep(2 * time.Second)
1143 err = ctrl.WaitUntilIdle(context.Background(), true)
1144 require.NoError(t, err)
1145 }
1146
1147 // Make sure there's time for the watcher to start
1148 awaitIdle()
1149
1150 testruntime.PutFiles(t, rt, id, map[string]string{
1151 "/data/foo.csv": `a,b,c,d,e
11521,2,3,4,5
11531,2,3,4,5
11541,2,3,4,5
1155`,
1156 "/sources/foo.yaml": `
1157connector: local_file
1158path: data/foo.csv
1159`,
1160 })
1161 awaitIdle()
1162 testruntime.RequireReconcileState(t, rt, id, 2, 0, 0)
1163 testruntime.RequireOLAPTable(t, rt, id, "foo")
1164 _, sourceRes := newSource("foo", "data/foo.csv", localFileHash(t, rt, id, []string{"data/foo.csv"}), 3)
1165 testruntime.RequireResource(t, rt, id, sourceRes)
1166
1167 testruntime.PutFiles(t, rt, id, map[string]string{
1168 "/models/bar.sql": `SELECT * FROM foo`,
1169 })
1170 awaitIdle()
1171 testruntime.RequireReconcileState(t, rt, id, 3, 0, 0)
1172 testruntime.RequireOLAPTable(t, rt, id, "bar")
1173 _, modelRes := newModel("SELECT * FROM foo", "bar", "foo", 3)
1174 testruntime.RequireResource(t, rt, id, modelRes)
1175
1176 testruntime.PutFiles(t, rt, id, map[string]string{
1177 "/metrics/dash.yaml": `
1178version: 1
1179type: metrics_view
1180display_name: Dash

Callers

nothing calls this directly

Calls 11

NewInstanceWithOptionsFunction · 0.92
PutFilesFunction · 0.92
RequireReconcileStateFunction · 0.92
RequireOLAPTableFunction · 0.92
RequireResourceFunction · 0.92
newSourceFunction · 0.85
localFileHashFunction · 0.85
newModelFunction · 0.85
ControllerMethod · 0.80
newMetricsViewFunction · 0.70
WaitUntilIdleMethod · 0.45

Tested by

no test coverage detected