Skip to content

Conversation

@machichima
Copy link
Member

@machichima machichima commented Dec 29, 2025

Tracking issue

Closes #6818
Closes #6819

Why are the changes needed?

Add api test for task service.

What changes were proposed in this pull request?

  • Create the structure of running API test, including setup the test server, DB, and clean up for each test
  • Add API test for DeployTask

How was this patch tested?

  • API test
image

Labels

Please add one or more of the following labels to categorize your PR:

  • added: For new features.
  • changed: For changes in existing functionality.
  • deprecated: For soon-to-be-removed features.
  • removed: For features being removed.
  • fixed: For any bug fixed.
  • security: In case of vulnerabilities

This is important to improve the readability of release notes.

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

@machichima machichima changed the title Task service api test [Test] Add Task service api test structure and for DeployTask Dec 29, 2025
Copy link
Contributor

@popojk popojk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@machichima machichima merged commit ba49efe into flyteorg:v2 Dec 29, 2025
4 checks passed
Copy link

@yuhuan130 yuhuan130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GREAT WORK!

Comment on lines +10 to +15
func getEnvOrDefault(key, defaultValue string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultValue
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think this function was never used right 🤔

Comment on lines +88 to +98
go func() {
log.Printf("Test server starting on %s", endpoint)
if err := testServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Printf("Server error: %v", err)
}
}()

// Wait for server to be ready
if !waitForServer(endpoint, 10*time.Second) {
log.Fatal("Test server failed to start")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the server fails to bind to port 8091, besides logging, the code still keeps on running for 10 seconds. Do you think it's a good idea to stop early whenever the server fails to bind in the goroutine?


### Run API tests

Pleaes ensure the service is started by following [Quick Start with SQLite](#quick-start-with-sqlite) section

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small typo here -> "Please"

Comment on lines +151 to +155
for _, table := range tables {
if err := testDB.Exec(fmt.Sprintf("DELETE FROM %s", table)).Error; err != nil {
t.Logf("Warning: Failed to cleanup table %s: %v", table, err)
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll be better to change it to t.Fatalf() to stop the function as soon as the deletion of database was errored, so we wouldn't have used the broken database down the way. What do you think about this?


// Delete all records from all tables
// Order matters due to foreign key constraints (if any)
tables := []string{"tasks", "task_specs", "actions"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I acknowledge we only got these three tables right now. But what do you feel about sending query for dynamic table check?

)

const (
testPort = 8091 // Different port to avoid conflicts with main service

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just pure out of curiosity. Will people have their port 8091 being used❓

Comment on lines +104 to +115
// Teardown: Stop server
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := testServer.Shutdown(shutdownCtx); err != nil {
log.Printf("Test server shutdown error: %v", err)
}
log.Println("Test server stopped")

// Cleanup: Remove test database file
if err := os.Remove(testDBFile); err != nil && !os.IsNotExist(err) {
log.Printf("Warning: Failed to remove test database: %v", err)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here cleanup only runs if we reach the end of TestMain. If there’s a panic or early exit during setup, the server and DB file might be left around. Would it make sense to move the cleanup into the deferred block so it always runs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants