Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions posts_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ func (c *Client) CreateCarouselPost(ctx context.Context, content *CarouselPostCo
return nil, err
}

// Wait for all child containers to be ready before creating the carousel container
// The Threads API requires child containers to be in FINISHED status
for i, childID := range content.Children {
if err := c.waitForContainerReady(ctx, ContainerID(childID), DefaultContainerPollMaxAttempts, DefaultContainerPollInterval); err != nil {
return nil, fmt.Errorf("child container %d (%s) not ready: %w", i+1, childID, err)
}
}

// Create container first
containerID, err := c.createCarouselContainer(ctx, content)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ func TestIntegration_PostOperations(t *testing.T) {
}
t.Logf("Created second media container: %s", container2)

// Wait a moment for containers to be ready
time.Sleep(1 * time.Second)
// Note: No sleep needed - CreateCarouselPost waits for child containers to be ready

// Create carousel post
content := &threads.CarouselPostContent{
Expand Down Expand Up @@ -681,7 +680,7 @@ func TestIntegration_SpoilersAndTextAttachments(t *testing.T) {
return
}

time.Sleep(1 * time.Second)
// Note: No sleep needed - CreateCarouselPost waits for child containers to be ready

// Create carousel with all media marked as spoilers
content := &threads.CarouselPostContent{
Expand Down
Loading