Skip to content

Commit

Permalink
integration test + refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
deniseli committed Oct 3, 2024
1 parent 2c5c44b commit 10e89e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
26 changes: 26 additions & 0 deletions backend/controller/console/console_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,29 @@ func TestConsoleGetModules(t *testing.T) {
}),
)
}

// StreamModules calls console service GetModules and returns the response.
//
// This action is defined here vs. actions.go because it is only used in this test file.
func StreamModules(onResponse func(t testing.TB, resp *connect.ServerStreamForClient[pbconsole.StreamModulesResponse])) in.Action {
return func(t testing.TB, ic in.TestContext) {
in.Infof("StreamModules")
modules, err := ic.Console.StreamModules(ic.Context, &connect.Request[pbconsole.StreamModulesRequest]{})
assert.NoError(t, err)
onResponse(t, modules)
}
}

func TestConsoleStreamModules(t *testing.T) {
in.Run(t,
in.CopyModule("console"),
in.Deploy("console"),
StreamModules(func(t testing.TB, stream *connect.ServerStreamForClient[pbconsole.StreamModulesResponse]) {
for stream.Receive() {
assert.Equal(t, 2, len(stream.Msg().Modules))
assert.Equal(t, "console", stream.Msg().Modules[0].Name)
assert.Equal(t, "builtin", stream.Msg().Modules[1].Name)
}
}),
)
}
3 changes: 1 addition & 2 deletions frontend/console/src/api/modules/use-stream-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ConsoleService } from '../../protos/xyz/block/ftl/v1/console/console_co
import type { Module } from '../../protos/xyz/block/ftl/v1/console/console_pb'

const streamModulesKey = 'streamModules'
const updateIntervalMs = 60 * 1000

export const useStreamModules = () => {
const client = useClient(ConsoleService)
Expand All @@ -19,7 +18,7 @@ export const useStreamModules = () => {
try {
console.debug('streaming modules')
let hasModules = false
for await (const response of client.streamModules({ updateInterval: { seconds: BigInt(0), nanos: updateIntervalMs * 1000 }, query: {} }, { signal })) {
for await (const response of client.streamModules({}, { signal })) {
console.debug('stream-modules-response:', response)
if (response.modules) {
hasModules = true
Expand Down

0 comments on commit 10e89e1

Please sign in to comment.