Skip to content

daytrader-go: tests - #7

Open
devin-ai-integration[bot] wants to merge 1 commit into
migration/daytrader-gofrom
devin/1794800000-go-tests
Open

devin-ai-integration[bot] wants to merge 1 commit into
migration/daytrader-gofrom
devin/1794800000-go-tests

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Ports the 24 JUnit 5 tests in daytrader3-ee6-ejb/src/test to Go and adds tests for the scaffold packages. Only new *_test.go files; no scaffold file, go.mod, Makefile, docs, parity or CI change.

Database tests skip with t.Skip when TEST_DATABASE_URL is unset. When it is set, each package works in its own schema (daytrader_test_store, daytrader_test_seed, daytrader_test_web, via search_path), so packages run in parallel and a database seeded by make go-run (schema public) is not touched.

cd daytrader-go && go vet ./... && go test ./...          # no database needed
make go-db
TEST_DATABASE_URL='postgres://daytrader:daytrader@localhost:55432/daytrader?sslmode=disable' go test ./...

Gate, as observed locally (Go 1.27.0)

Check Result
gofmt -l . clean
go vet ./... clean
go test ./... (no database) ok in all 6 packages with tests; 25 tests skipped (22 database tests + the 3 below)
go test -race ./... with TEST_DATABASE_URL against make go-db ok; 79 tests pass, 3 skipped (below); also -count=3

Parity: this workstream has no target scenarios and make parity was not run, against Liberty or against the Go target, alone or combined with sibling branches. No scenario is claimed as PASS.

Legacy test -> Go test

Legacy class / method Go test
FinancialUtilsTest.computeGainSubtractsOpenFromCurrentAtScaleTwo javafmt.TestComputeGainSubtractsOpenFromCurrentAtScaleTwo
FinancialUtilsTest.computeGainRejectsValuesThatNeedRounding Behaviour not in Go. javafmt.ComputeGain returns a decimal and cannot throw. TestComputeGainKeepsExtraDecimalsInsteadOfThrowing pins what Go does (1.005, printed 1.01)
FinancialUtilsTest.computeGainPercentIsRelativeToOpenBalance javafmt.TestComputeGainPercentIsRelativeToOpenBalance (plus half-up cases)
FinancialUtilsTest.computeGainPercentIsZeroWhenOpenBalanceIsZero javafmt.TestComputeGainPercentIsZeroWhenOpenBalanceIsZero
FinancialUtilsTest.computeHoldingsTotalSumsPurchasePriceTimesQuantity javafmt.TestHoldingsTotalSumsPurchasePriceTimesQuantity
FinancialUtilsTest.computeHoldingsTotalHandlesNullAndEmpty javafmt.TestHoldingsTotalHandlesNilAndEmpty
FinancialUtilsTest.printGainHtmlUsesRedDownArrowForLossesAndGreenUpArrowOtherwise javafmt.TestPrintGainHTMLUsesRedDownArrowForLossesAndGreenUpArrowOtherwise (whole string)
FinancialUtilsTest.printGainPercentHtmlPrefixesPositiveValuesWithPlus javafmt.TestPrintGainPercentHTMLPrefixesPositiveValuesWithPlus
FinancialUtilsTest.printChangeHtmlRendersRawDouble javafmt.TestPrintChangeHTMLRendersRawDouble
FinancialUtilsTest.printQuoteLinkPointsAtQuotesAction javafmt.TestPrintQuoteLinkPointsAtQuotesAction
TradeConfigTest.defaultsMatchTheShippedConfiguration config.TestFromEnvDefaultsMatchTheShippedConfiguration. runTimeMode (EJB3) has no Go equivalent; DATASOURCE became DATABASE_URL
TradeConfigTest.runTimeModeIsMatchedByDisplayNameIgnoringCaseAndWhitespace Not ported: no Go equivalent. There is one runtime mode and no setConfigParam. Case-insensitive matching of the one remaining enum: config.TestOrderProcessingModeIsMatchedIgnoringCase
TradeConfigTest.unknownEnumValueLeavesSettingUnchanged config.TestOrderProcessingModeIsMatchedIgnoringCase + config.TestUnknownOrderProcessingModeIsAnError (Go refuses to start instead of keeping the old value)
TradeConfigTest.nullOrBlankParametersAreIgnored config.TestFromEnvEmptyValuesFallBackToDefaults (an empty variable keeps the default; there are no null parameter names)
TradeConfigTest.webInterfaceWorkloadMixAndCachingTypeAreParsed Not ported: no Go equivalent. webInterface, workloadMix and cachingType do not exist in config.Config
TradeConfigTest.numericLimitsAreParsedAndBadNumbersAreIgnored config.TestNumericLimitsAreParsedAndBadNumbersAreErrors (a bad number is a start-up error) and config.TestNumericValuesAreTrimmedLikeSetConfigParam (skipped, see below)
TradeConfigTest.orderFeeAppliesToBuyAndSellOnly config.TestOrderFeeAppliesToBuyAndSellOnly
TradeConfigTest.nextUserIdWrapsAtMaxUsers Not ported: no Go equivalent. TradeConfig.nextUserID (load-generator helper) is not in the scaffold
TradeConfigTest.randomSymbolsStayInsideTheQuotePopulation No rndSymbol function; the same bound (s:0 .. s:MAX_QUOTES-2) is asserted on every seeded holding in seed.TestBuildDBPopulatesUsersQuotesHoldingsAndOrders (database)
TradeConfigTest.priceChangeFactorStaysWithinTwentyPercent seed.TestPriceChangeFactorStaysWithinTwentyPercent
EntityMappingTest.entitiesMapToTheDerbyTablesWithNonNullIds daytradergo.TestSchemaKeepsTheLegacyTablesWithNonNullIDs (embedded migration, no database) and seed.TestBuildTablesCreatesTheLegacyTablesWithNonNullIDs (information_schema, database)
EntityMappingTest.equalityIsByIdentifierOnly Not ported: no Go equivalent. The store structs have no equals/hashCode
EntityMappingTest.orderTypeAndStatusPredicates Not ported: no Go equivalent. store.Order has no isBuy/isSell/isOpen/isCompleted; feature areas compare OrderType/OrderStatus strings
EntityMappingTest.cancelMarksOrderCancelledAndCompleted Not ported: no Go equivalent. store.Order has no cancel()

New scaffold tests

  • internal/config: defaults, every override, nil lookup reads the process environment, first bad value is reported, bad flags.
  • internal/javafmt: Date (java.util.Date.toString in UTC), Double, Money, link escaping.
  • internal/web (httptest, no database; the pool points at a closed port and never connects): front controller (no action, not logged in, unknown action, public action, POST form, 405), session cookie, login then protected action, Invalidate, 30 minute idle timeout, registry (duplicate panics, sorted list, RegisterWelcome, RegisterErrorPage), Forward/Attr/Param, Render, panic -> 500, routes under the context path and REST root, static files, / redirect, health DOWN, /config, layout and closed-orders alert HTML, template functions. With a database: health UP, /config?action=buildDBTables|buildDB, the closed-orders alert shown once.
  • internal/store (database): NextID (starts at 0, block reservation in keygenejb, key names independent, second store / ResetKeys start at the next block, existing key row, unique under concurrency, default block size), ClosedOrders (closed only, ordered, returned as completed, once, per user), single-row reads and ErrNotFound, list ordering, InTx commit and rollback.
  • internal/seed (database, MAX_USERS=25, MAX_QUOTES=12): BuildTables (tables, ids, drops data and key blocks, recovers a partly dropped schema), BuildDB (counts, profiles, uid:0 opens with 1,000,000, balance = open balance - sum(quantity x price + 24.95), order/holding links, quote volume = shares bought, keygenejb blocks and the next NextID, same random seed -> same data, UPDATE_QUOTE_PRICES=false, MAX_QUOTES=1).

Scaffold findings (not fixed here; scaffold files are not mine to edit)

Each is a skipped assertion with the reason in the t.Skip message, so the gate stays green:

  1. config.FromEnv does not trim whitespace: MAX_USERS=" 200 " is an error, legacy setConfigParam reads it as 200. TestNumericValuesAreTrimmedLikeSetConfigParam.
  2. javafmt.Double prints 10000000.0 for 1e7 and 0.0001 for 1e-4; Java Double.toString prints 1.0E7 and 1.0E-4. The function's comment limits it to "the magnitudes DayTrader shows"; a quote volume of 10,000,000 or more would differ from legacy. TestDoubleUsesScientificNotationOutsideTheJavaPlainRange.
  3. store.Scan* fail on NULL in the nullable legacy columns (cannot scan NULL into *string), where JPA gives a null field. The seeder never writes NULL there. TestRowsWithNullColumnsCanBeRead.

Different from legacy on purpose (scaffold decisions the tests pin)

  • A bad number, flag or ORDER_PROCESSING_MODE is a start-up error, not silently ignored.
  • ComputeGain does not throw for a third decimal place.
  • PrintQuoteLink HTML-escapes the symbol.

Scaffold requests

  • CI does not run the Go gate: .github/workflows/ci.yml has no go vet / go test step and no PostgreSQL service with TEST_DATABASE_URL, so the database tests only run locally.
  • Decide on findings 1-3 above; un-skip the three tests when fixed.

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/0b73d91748634cd6addb1a7994bdb332
Open in Devin Desktop: https://partner-workshops.devinenterprise.com/desktop/session/0b73d91748634cd6addb1a7994bdb332?variant=devin
Requested by: @sumitshatwara

@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

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.

1 participant